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

Unicode string may have no paddings #34

Closed gyk closed 2 years ago

gyk commented 2 years ago

I have a PSD file where the unicode string inside luni additional layer info has neither null bytes nor paddings:

38 42 49 4D 6C 75 6E 69 00 00 00 06 00 00 00 01 00 31    8BIMluni.........1

However, the current implementation decodes it as a unicode string with a padding length of 4: https://github.com/chinedufn/psd/blob/master/src/sections/layer_and_mask_information_section/mod.rs#L424, so all the parsed data after it are messed up.

It seems unicode string may or may not have paddings, depending on the section length and the absolute position of file cursor. References:

Just seeking to beginning_position + additional_layer_info_len seems to be the easiest solution.

chinedufn commented 2 years ago

Ah, thanks for the bug report. I'd be happy to review a PR that fixes this!

gyk commented 2 years ago

Besides 'luni', I'm not sure whether the unicode string of "name from classID" uses paddings. PSD.rb apparently reads no paddings: link. Maybe read_unicode_string should default to read_unicode_string_padding(1)?

chinedufn commented 2 years ago

Ah, thanks for researching this!

I think we'd just want to add test fixture PSDs with different layer types and see whether or not they pass. Then if they fail modify the code to make them pass.