mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 11:05:29 -04:00
TMI-22: Changed IIOException to warning for images with single chunk ICC_PROFILE with bad index/count.
This commit is contained in:
parent
75c09d3aef
commit
c2245a503d
@ -731,7 +731,7 @@ public class JPEGImageReader extends ImageReaderBase {
|
||||
int chunkCount = stream.readUnsignedByte();
|
||||
|
||||
if (chunkNumber != 1 && chunkCount != 1) {
|
||||
throw new IIOException(String.format("Bad number of 'ICC_PROFILE' chunks: %d of %d.", chunkNumber, chunkCount));
|
||||
processWarningOccurred(String.format("Bad number of 'ICC_PROFILE' chunks: %d of %d.", chunkNumber, chunkCount));
|
||||
}
|
||||
|
||||
return readICCProfileSafe(stream);
|
||||
@ -744,7 +744,7 @@ public class JPEGImageReader extends ImageReaderBase {
|
||||
|
||||
if (chunkNumber < 1) {
|
||||
// Some weird JPEGs use 0-based indexes... count == 0 and all numbers == 0. Ignore these profiles
|
||||
processWarningOccurred("Invalid 'ICC_PROFILE' chunk index: " + chunkNumber + ". Ignoring ICC profile.");
|
||||
processWarningOccurred(String.format("Invalid 'ICC_PROFILE' chunk index: %d. Ignoring ICC profile.", chunkNumber));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -753,7 +753,7 @@ public class JPEGImageReader extends ImageReaderBase {
|
||||
// Others use count == 1, and all numbers == 1.
|
||||
// Handle these by issuing warning
|
||||
badICC = true;
|
||||
processWarningOccurred("Unexpected 'ICC_PROFILE' chunk count: " + chunkCount + ". Ignoring count, assuming " + segments.size() + " chunks in sequence.");
|
||||
processWarningOccurred(String.format("Unexpected 'ICC_PROFILE' chunk count: %d. Ignoring count, assuming %d chunks in sequence.", chunkCount, segments.size()));
|
||||
}
|
||||
|
||||
int count = badICC ? segments.size() : chunkCount;
|
||||
|
@ -34,6 +34,7 @@ import org.junit.Test;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.event.IIOReadWarningListener;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
@ -46,6 +47,10 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* JPEGImageReaderTest
|
||||
@ -271,6 +276,32 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
|
||||
// TODO: Need to test colors!
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidICCSingleChunkBadSequence() throws IOException {
|
||||
// Regression
|
||||
// Single segment ICC profile, with chunk index/count == 0
|
||||
|
||||
JPEGImageReader reader = createReader();
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/invalid-icc-single-chunk-bad-sequence-number.jpg")));
|
||||
|
||||
assertEquals(1772, reader.getWidth(0));
|
||||
assertEquals(2126, reader.getHeight(0));
|
||||
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
param.setSourceRegion(new Rectangle(reader.getWidth(0), 8));
|
||||
|
||||
IIOReadWarningListener warningListener = mock(IIOReadWarningListener.class);
|
||||
reader.addIIOReadWarningListener(warningListener);
|
||||
|
||||
BufferedImage image = reader.read(0, param);
|
||||
|
||||
assertNotNull(image);
|
||||
assertEquals(1772, image.getWidth());
|
||||
assertEquals(8, image.getHeight());
|
||||
|
||||
verify(warningListener).warningOccurred(eq(reader), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasThumbnailNoIFD1() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 230 KiB |
Loading…
x
Reference in New Issue
Block a user