webtoon / psd

Fast zero-dependency PSD parser for the web and Node.js
https://webtoon.github.io/psd
MIT License
1.21k stars 55 forks source link

Opening a PSD file throws "invalid typed array length" error #40

Closed nedpals closed 2 years ago

nedpals commented 2 years ago

I'm trying to open a PSD file i haved created from Photopea into the demo and after selecting the file, the preview did not worked and instead the demo threw an error:

image

When dissecting the stack trace, it leads me to this code which is in line 253 254: image

Hope it helps :wink: hoping to use it for a project

dlehdanakf commented 2 years ago

If it is not a security problem, can you attach the PSD file that caused the problem?

nedpals commented 2 years ago

@dlehdanakf Sure thing: https://we.tl/t-G2lVvra3Uj

There are two files in that zip: test.psd and test2.psd

Here's test.psd image

Here's test2.psd . This is just a modified version of test.psd that is parseable by the package. image

image

What I found when scrutinizing the test.psd file is that when I delete the gradient layer, the library has managed to parse it successfully.

Hope it helps 😃

pastelmind commented 2 years ago

Thank you. It appears that the gradient fill layer does not contain any image data--I assume that Photoshop synthesizes the image on the fly when I open the PSD file--and we weren't prepared for such an edge case.

I'm pushing a fix that renders the layer as an empty 1x1 image. It's not ideal, but synthesizing the gradient fill is currently beyond our goals.

nedpals commented 2 years ago

@pastelmind No worries! Atleast it doesn't throw an error now 😄 Great job btw

chao-mu commented 7 months ago

I think there might be a regression of this fix readLayerRecordsAndChannels.ts. readLayerRecordsAndChannels is failing with a RangeError again and it looks like the code may not longer account for this case. Unfortunately I do not have access to photoshop to further debug this issue. Let me know and I can send you a reproduction, but I can't post publically.