Fix bounds issue in some v2 PICT files (#1129)

x2 and y2 were swapped over, resulting in an "invalid bounds" exception with -ve height on some nonV2Ext images,
see for example CatDV==2.0=1=.pict or Picture14.pict

Co-authored-by: Harald Kuhr <harald.kuhr@gmail.com>
This commit is contained in:
Rolf Howarth 2025-05-30 14:59:00 +01:00 committed by GitHub
parent 1bef35daba
commit 66363f8d09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 1 deletions

View File

@ -254,8 +254,8 @@ public final class PICTImageReader extends ImageReaderBase {
// the default Mac screen resolution and the image resolution // the default Mac screen resolution and the image resolution
// int y, x, w(?), h (fixed point) // int y, x, w(?), h (fixed point)
double y2 = PICTUtil.readFixedPoint(pStream);
double x2 = PICTUtil.readFixedPoint(pStream); double x2 = PICTUtil.readFixedPoint(pStream);
double y2 = PICTUtil.readFixedPoint(pStream);
double w2 = PICTUtil.readFixedPoint(pStream); // ?! double w2 = PICTUtil.readFixedPoint(pStream); // ?!
double h2 = PICTUtil.readFixedPoint(pStream); double h2 = PICTUtil.readFixedPoint(pStream);

View File

@ -84,6 +84,8 @@ public class PICTImageReaderTest extends ImageReaderAbstractTest<PICTImageReader
new TestData(getClassLoaderResource("/pict/FC10.PCT"), new Dimension(2265, 2593)), new TestData(getClassLoaderResource("/pict/FC10.PCT"), new Dimension(2265, 2593)),
// 1000 DPI with bounding box not matching DPI // 1000 DPI with bounding box not matching DPI
new TestData(getClassLoaderResource("/pict/oom.pict"), new Dimension(1713, 1263)), new TestData(getClassLoaderResource("/pict/oom.pict"), new Dimension(1713, 1263)),
new TestData(getClassLoaderResource("/pict/CatDV==2.0=1=.pict"), new Dimension(375, 165)),
new TestData(getClassLoaderResource("/pict/Picture14.pict"), new Dimension(404, 136)),
new TestData(getClassLoaderResource("/pict/J19.pict"), new Dimension(640, 480)), new TestData(getClassLoaderResource("/pict/J19.pict"), new Dimension(640, 480)),
// Sample data from http://developer.apple.com/documentation/mac/QuickDraw/QuickDraw-458.html // Sample data from http://developer.apple.com/documentation/mac/QuickDraw/QuickDraw-458.html
@ -249,6 +251,23 @@ public class PICTImageReaderTest extends ImageReaderAbstractTest<PICTImageReader
reader.read(0); reader.read(0);
} }
@Test
public void testBoundsIssue() throws IOException {
PICTImageReader reader = createReader();
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/pict/Picture14.pict"))) {
reader.setInput(stream);
BufferedImage image = reader.read(0, null);
assertRGBEquals("RGB values differ", 0xffcccccc, image.getRGB(4, 4), 1); // was transparent 00ffffff
assertRGBEquals("RGB values differ", 0xffcccccc, image.getRGB(5, 118), 1); // was red ffcc6666
assertRGBEquals("RGB values differ", 0xffcc6666, image.getRGB(28, 60), 1); // was grey ffcccccc
}
finally {
reader.dispose();
}
}
@Test @Test
public void testQTMaskBytesSkipped() throws IOException { public void testQTMaskBytesSkipped() throws IOException {
assumeTrue(ImageIO.getImageReadersByFormatName("TIFF").hasNext(), "No TIFF plugin available, skipping test"); assumeTrue(ImageIO.getImageReadersByFormatName("TIFF").hasNext(), "No TIFF plugin available, skipping test");

Binary file not shown.