Skip to content

Conversation

@Etienne-Gautier
Copy link
Contributor

Context

I have see a user-uploaded file that psd-tools can't read. This file was produced by Affinity Photo 1.10.4 and exported as PSD.

The file was failing in the Stroke constructor at assert self._data.classID == b"strokeStyle". Instead the classId is Strk

Photoshop doesn't have a problem opening this file, and does so without warning. So the classId check can be either relaxed (accept 2 values) or removed entirely.

Just wondering if it is best to allow 2 values here, or to remove the assert altogether?

@kyamagu
Copy link
Contributor

kyamagu commented Dec 15, 2022

The ID seems to be the Event enum value. I do not know what values are possible here, but skipping the check does not sound safe. At least there should be a warning for unknown values.

Can you also come up with a test case?

@Etienne-Gautier
Copy link
Contributor Author

I do not know what values are possible here, but skipping the check does not sound safe

I suggested removing the check because it seems like this is the only place where we assert for a specific classID in a constructor.

I'll try to generate a new file with this same issue, but the one I have right now has customer data and I can't share it

@Etienne-Gautier
Copy link
Contributor Author

Etienne-Gautier commented Dec 19, 2022

I'll try to generate a new file with this same issue, but the one I have right now has customer data and I can't share it

Still no luck generating a file with that issue despite trying a few different shapes and versions of this affinity software. Such files definitely exists in the wild.

Worst case, I can still get away with a monkey patch if you don't want to accept this PR without a demo file (which I totally understand).

def __init__(self, data):
self._data = data
assert self._data.classID == b'strokeStyle'
assert self._data.classID == b'strokeStyle' or self._data.classID == b'Strk'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Etienne-Gautier Can you do something like the following?

from psd_tools.terminology import Event

if self._data.classID not in (b'strokeStyle', Event.Stroke):
    logger.warning("Unknown class ID found: {}".format(self._data.classID))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK not to have a fixture file for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I'll make that change, I've also just managed to get down to a simple version of the file that reproduces the issue (zipped because github doesn't allow PSDs):
user file cycled.psd.zip

Copy link
Contributor

@kyamagu kyamagu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kyamagu
Copy link
Contributor

kyamagu commented Dec 20, 2022

The CI error is likely due to the outdated cibuildwheel version.

@kyamagu kyamagu merged commit 128d2e6 into psd-tools:main Dec 20, 2022
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

Successfully merging this pull request may close these issues.

2 participants