mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-10-04 11:26:44 -04:00
TMI-JPEG: More lenient segment parsing, now allows 0xFF padding between segments + fixed an NPE in JPEGImageReader if the parsing fails.
This commit is contained in:
@@ -153,11 +153,18 @@ public final class JPEGSegmentUtil {
|
||||
}
|
||||
}
|
||||
|
||||
static JPEGSegment readSegment(final ImageInputStream stream, Map<Integer, List<String>> segmentIdentifiers) throws IOException {
|
||||
static JPEGSegment readSegment(final ImageInputStream stream, final Map<Integer, List<String>> segmentIdentifiers) throws IOException {
|
||||
int marker = stream.readUnsignedShort();
|
||||
|
||||
// Skip over 0xff padding between markers
|
||||
while (marker == 0xffff) {
|
||||
marker = (marker & 0xff) << 8 | stream.readUnsignedByte();
|
||||
}
|
||||
|
||||
if ((marker >> 8 & 0xff) != 0xff) {
|
||||
throw new IIOException(String.format("Bad marker: %04x", marker));
|
||||
}
|
||||
|
||||
int length = stream.readUnsignedShort(); // Length including length field itself
|
||||
|
||||
byte[] data;
|
||||
@@ -196,7 +203,7 @@ public final class JPEGSegmentUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
public boolean contains(final Object o) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -208,13 +215,13 @@ public final class JPEGSegmentUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> get(Object key) {
|
||||
public List<String> get(final Object key) {
|
||||
return key instanceof Integer && JPEGSegment.isAppSegmentMarker((Integer) key) ? ALL_IDS : null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
public boolean containsKey(final Object key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -226,7 +233,7 @@ public final class JPEGSegmentUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> get(Object key) {
|
||||
public List<String> get(final Object key) {
|
||||
return containsKey(key) ? ALL_IDS : null;
|
||||
|
||||
}
|
||||
|
@@ -196,4 +196,17 @@ public class JPEGSegmentUtilTest {
|
||||
assertEquals(JPEG.APP14, segments.get(21).marker());
|
||||
assertEquals("Adobe", segments.get(21).identifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadPaddedSegments() throws IOException {
|
||||
List<JPEGSegment> segments = JPEGSegmentUtil.readSegments(getData("/jpeg/jfif-padded-segments.jpg"), JPEGSegmentUtil.APP_SEGMENTS);
|
||||
assertEquals(3, segments.size());
|
||||
|
||||
assertEquals(JPEG.APP0, segments.get(0).marker());
|
||||
assertEquals("JFIF", segments.get(0).identifier());
|
||||
assertEquals(JPEG.APP2, segments.get(1).marker());
|
||||
assertEquals("ICC_PROFILE", segments.get(1).identifier());
|
||||
assertEquals(JPEG.APP1, segments.get(2).marker());
|
||||
assertEquals("Exif", segments.get(2).identifier());
|
||||
}
|
||||
}
|
||||
|
BIN
imageio/imageio-metadata/src/test/resources/jpeg/jfif-padded-segments.jpg
Executable file
BIN
imageio/imageio-metadata/src/test/resources/jpeg/jfif-padded-segments.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
Reference in New Issue
Block a user