Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DescriptorStructure can occur inside an ImageResourcesBlock #40

Open
joedevivo opened this issue Dec 14, 2022 · 1 comment
Open

DescriptorStructure can occur inside an ImageResourcesBlock #40

joedevivo opened this issue Dec 14, 2022 · 1 comment

Comments

@joedevivo
Copy link

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
Copy link
Owner

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

fn image_check_1x1p_bound_field() {
let psd = include_bytes!("./fixtures/two-layers-red-green-1x1.psd");
let psd = Psd::from_bytes(psd).unwrap();
let descriptors = match &psd.resources()[0] {
ImageResource::Slices(s) => s.descriptors(),
};
let descriptor = descriptors.get(0).unwrap();
let bounds = descriptor.fields.get("bounds").unwrap();
if let DescriptorField::Descriptor(d) = bounds {
match d.fields.get("Rght").unwrap() {
DescriptorField::Integer(v) => assert_eq!(*v, 1),
_ => panic!("expected integer"),
}
match d.fields.get("Btom").unwrap() {
DescriptorField::Integer(v) => assert_eq!(*v, 1),
_ => panic!("expected integer"),
}
} else {
panic!("expected descriptor");
}
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants