chinedufn / psd

A Rust API for parsing and working with PSD files.
https://chinedufn.github.io/psd
Apache License 2.0
265 stars 40 forks source link

DescriptorStructure can occur inside an ImageResourcesBlock #40

Open joedevivo opened 1 year ago

joedevivo commented 1 year ago

Inside read_resource_block, some resource_ids like 3000 expect the value to be a Descriptor. I actually encountered this because when it is a Descriptor, I'm not sure what the deal is with data_len, but it is way off. This caused an Index out of bounds error, as it was trying to read the cursor way too far.

I tried to reverse engineer the binary, along with reading from the PSD file spec, but there's still just some bits in there I can't figure out, especially at the beginning with the data length.

I think something similar to what you're doing in read_slice_block could work, but I'm not quite sure how to set that up properly in read_resource_block

chinedufn commented 1 year ago

Hey, thanks for reporting this issue.

Can you create a minimal PSD that can be used to reproduce this issue?

Here are some examples https://github.com/chinedufn/psd/tree/master/tests/fixtures

Then we'd add a test to the image resources section. Here's an example test https://github.com/chinedufn/psd/blob/3d4c1960fc141bbf13710646e11870b3a3b97898/tests/image_resources_section.rs#L8-L32

From there we can figure out how to get the test passing.