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

Fail to generate PNG file from PSD when update 3.6.1 to 3.9.4 #719

Closed
dsboo opened this issue Dec 20, 2022 · 4 comments
Closed

Fail to generate PNG file from PSD when update 3.6.1 to 3.9.4 #719

dsboo opened this issue Dec 20, 2022 · 4 comments

Comments

@dsboo
Copy link

dsboo commented Dec 20, 2022

Describe the bug
When I use 3.9.4 latest version, fail to generate PNG file from specific PSD.
But When I use 3.6.1 version, success to generate PNG file from that(failed with 3.9.4).
If you need more infomation, tell me freely.

Version information

  1. The version of the TwelveMonkeys ImageIO library in use.
    3.9.4

  2. The exact output of java --version (or java -version for older Java releases).

openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment 18.9 (build 11.0.6+10)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.6+10, mixed mode)

  1. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.
    CentOS Linux 7 (Core)

To Reproduce

1. Open PSD file in java code
2. make BufferedImage from PSD file

Expected behavior
generate PNG file from PSD normally

Example code
If you need, i will write unit test code.

File psdFile = new File("src/main/resources/sample.psd");
InputStream targetStream = FileUtils.openInputStream(psdFile);
BufferedImage image = ImageIO.read(inputStream);
ImageIO.write(image, "PNG", new CustomByteArrayOutputStream());

Sample file(s)
I cannot attached, because it's customer's.

Stak trace

java.util.EmptyStackException: null
  at java.base/java.util.Stack.peek(Stack.java:102)
  at java.base/java.util.Stack.pop(Stack.java:84)
  at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.readLayerInfo(PSDImageReader.java:1051)
  at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.readLayerAndMaskInfo(PSDImageReader.java:920)
  at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.getNumImages(PSDImageReader.java:1220)
  at com.twelvemonkeys.imageio.ImageReaderBase.checkBounds(ImageReaderBase.java:190)
  at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.read(PSDImageReader.java:368)
  at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1468)
  at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1363)

Additional context

@haraldk
Copy link
Owner

haraldk commented Dec 20, 2022

Thanks for reporting!

I can see from the stack trace that this happens during reading of the PSD (layer info), it's not directly related to the conversion to PNG format. But, there's something with the grouping of the layers in the file you use, that is either non-spec or we don't handle it properly... Probably the latter. Layer group support was introduced in 3.9.0, so I guess any version below that will work.

Unfortunately, I can't say much more without having a sample image, or at least a dump of the layer structure. All my sample files can be converted using that code (assuming inputStream and targetStream should be the same, and replacing code I don't have).

Are you able to export a copy of the file with the image data removed (but the layer structure intact)? Or if you can create a PSD with a similar layer structure that also expose this problem, that would also help.

@haraldk
Copy link
Owner

haraldk commented Jan 18, 2023

Closing as not reproducible. Please reopen if you find a sample that can be shared.

@haraldk haraldk closed this as completed Jan 18, 2023
@EvanDarwin
Copy link

EvanDarwin commented Jul 21, 2023

@haraldk I'm currently able to reproduce this issue on imageio-psd 3.9.4 (OpenJDK 18.0.2.1), and am able to provide a repro sample as well.

I have no reason to believe this file was created in a client other than modern Photoshop. Any time you could take to investigate this would be appreciated. 😄

Stack trace:

Exception in thread "main" java.util.EmptyStackException
	at java.base/java.util.Stack.peek(Stack.java:101)
	at java.base/java.util.Stack.pop(Stack.java:83)
	at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.readLayerInfo(PSDImageReader.java:1051)
	at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.readLayerAndMaskInfo(PSDImageReader.java:970)
	at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.getNumImages(PSDImageReader.java:1220)
	at com.twelvemonkeys.imageio.ImageReaderBase.checkBounds(ImageReaderBase.java:190)
	at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.getHeight(PSDImageReader.java:112)

Related repro code:

val psdImageReaderSpi = new PSDImageReaderSpi();
val imageReader = (PSDImageReader) psdImageReaderSpi.createReaderInstance(new Object());

val stream = ImageIO.createImageInputStream(in);
imageReader.setInput(stream);
int height = imageReader.getHeight(0); // Exception

Asset:
repro.psd.zip

@haraldk
Copy link
Owner

haraldk commented Oct 20, 2023

Hmm.. Sorry, I missed that you had submitted a way to reproduce this... However, I'm unable to reproduce the issue with the above code and attached file on the current master branch. So it seems the issue is resolved through some other fix. 😀

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

No branches or pull requests

3 participants