mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-04 00:00:01 -04:00
#713 PSD: Broken uncompressed reading from stream w/unknown length
(cherry picked from commit da800be8c8)
This commit is contained in:
@@ -103,7 +103,8 @@ final class PSDUtil {
|
||||
final int[] byteCounts, long compressedLength) throws IOException {
|
||||
switch (compression) {
|
||||
case PSD.COMPRESSION_NONE:
|
||||
return new SubImageInputStream(stream, stream.length());
|
||||
long streamLength = stream.length();
|
||||
return new SubImageInputStream(stream, streamLength < 0 ? Long.MAX_VALUE : streamLength);
|
||||
|
||||
case PSD.COMPRESSION_RLE:
|
||||
return new DirectImageInputStream(new SequenceInputStream(new LazyPackBitsStreamEnumeration(byteCounts, stream)));
|
||||
|
||||
@@ -31,10 +31,12 @@
|
||||
package com.twelvemonkeys.imageio.plugins.psd;
|
||||
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.DirectImageInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.twelvemonkeys.imageio.plugins.psd.PSDUtil.createDecompressorStream;
|
||||
@@ -65,6 +67,29 @@ public class PSDUtilDecompressorStreamTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUncompressedUnknownLength() throws IOException {
|
||||
// Data represents 3 x 3 raster with 8 bit samples, all 0x7f's
|
||||
byte[] data = new byte[] {
|
||||
0x7f, 0x7f, 0x7f,
|
||||
0x7f, 0x7f, 0x7f,
|
||||
0x7f, 0x7f, 0x7f
|
||||
};
|
||||
try (ImageInputStream input = createDecompressorStream(new DirectImageInputStream(new ByteArrayInputStream(data)), PSD.COMPRESSION_NONE, 3, 8, null, 9)) {
|
||||
byte[] row = new byte[3];
|
||||
|
||||
for (int y = 0; y < 3; y++) {
|
||||
input.readFully(row);
|
||||
|
||||
for (byte b : row) {
|
||||
assertEquals((byte) 0x7f, b);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(-1, input.read());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackBits() throws IOException {
|
||||
// Data represents 3 x 3 raster with 8 bit samples, all 42's
|
||||
|
||||
Reference in New Issue
Block a user