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

Some malformed PSD images never return from ImageIO.read() using 3.10.0 #860

Closed
wladimirleite opened this issue Nov 6, 2023 · 2 comments

Comments

@wladimirleite
Copy link
Contributor

Describe the bug
Testing release 3.10.0, I found a few malformed PSD images that never return from ImageIO.read() (once the reading function is called, no exception is thrown but it never returns). Using 3.9.4, an exception was thrown, as expected.

Version information

  1. The version of the TwelveMonkeys ImageIO library in use:
    3.10.0. It also happens using the master branch.

  2. The exact output of java --version:
    openjdk version "11.0.13" 2021-10-19 LTS
    OpenJDK Runtime Environment (build 11.0.13+8-LTS)
    OpenJDK 64-Bit Server VM (build 11.0.13+8-LTS, mixed mode, sharing)

  3. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc.
    I tested it on Windows 11.

To Reproduce
Run a simple standalone program (below), using the PSD ImageIO plugin 3.10.0.

Expected behavior
As the sample images are malformed/incomplete, an exception should be thrown.

Example code

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class PSDReadTest {
    public static void main(String[] args) throws IOException {
        File input = new File("1.psd"); // Input image
        File output = new File("1.png"); // Output image
        BufferedImage image = ImageIO.read(input);
        ImageIO.write(image, "png", output);
    }
}

Sample files
sample-psd-images.zip

Stack trace
Running with the test program using 3.10.0, no exception is thrown and the program never finishes.

Running with 3.9.4, I got the following exception, which was expected because the sample images are malformed/incomplete.

Exception in thread "main" java.io.EOFException: Unexpected end of PackBits stream
	at com.twelvemonkeys.io.enc.PackBitsDecoder.readFully(PackBitsDecoder.java:186)
	at com.twelvemonkeys.io.enc.PackBitsDecoder.decode(PackBitsDecoder.java:143)
	at com.twelvemonkeys.io.enc.DecoderStream.fill(DecoderStream.java:179)
	at com.twelvemonkeys.io.enc.DecoderStream.read(DecoderStream.java:123)
	at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:199)
	at com.twelvemonkeys.imageio.stream.DirectImageInputStream.read(DirectImageInputStream.java:73)
	at java.desktop/javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:351)
	at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.read8bitChannel(PSDImageReader.java:656)
	at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.readImageData(PSDImageReader.java:480)
	at com.twelvemonkeys.imageio.plugins.psd.PSDImageReader.read(PSDImageReader.java:429)
	at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1468)
	at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1315)
	at PSDReadTest.main(PSDReadTest.java:11)

Additional context
I found these 4 sample images that trigger the issue, testing with a set with 1,500 PSD files, collected from different sources, so it seems a somewhat rare issue.

Trying to trace down what is going on, I found out that the execution stops during stream.readFully(rowData, 0, channelWidth); in read8bitChannel method of PSDImageReader class. Not sure why, but it seems that readFully is waiting forever for bytes not available.

@haraldk
Copy link
Owner

haraldk commented Nov 7, 2023

Thanks for the report and sample files! 👍🏻

I can reproduce, the problem is related to some stream-optimizations I did. I'm writing a few tests, will have a fix soon.

@haraldk
Copy link
Owner

haraldk commented Nov 7, 2023

Fixed in lastest SNAPSHOT. There will be a 3.10.1 bug fix release soon.

@haraldk haraldk closed this as completed Nov 7, 2023
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

2 participants