Manual merge of #223

This commit is contained in:
Harald Kuhr 2016-04-21 15:30:20 +02:00
commit f382f4b5f9
3 changed files with 44 additions and 38 deletions

View File

@ -105,16 +105,16 @@ public final class EXIFReader extends MetadataReader {
} }
for (int i = 0; i < entryCount; i++) { for (int i = 0; i < entryCount; i++) {
try {
EXIFEntry entry = readEntry(pInput); EXIFEntry entry = readEntry(pInput);
if (entry == null) { if (entry != null) {
// System.err.println("Expected: " + entryCount + " values, found only " + i); entries.add(entry);
// TODO: Log warning? }
nextOffset = 0; }
catch (IIOException e) {
break; break;
} }
entries.add(entry);
} }
if (readLinked) { if (readLinked) {
@ -213,7 +213,9 @@ public final class EXIFReader extends MetadataReader {
offsets = (long[]) value; offsets = (long[]) value;
} }
else { else {
throw new IIOException(String.format("Unknown pointer type: %s", (value != null ? value.getClass() : null))); throw new IIOException(String.format("Unknown pointer type: %s", (value != null
? value.getClass()
: null)));
} }
return offsets; return offsets;
@ -224,11 +226,6 @@ public final class EXIFReader extends MetadataReader {
int tagId = pInput.readUnsignedShort(); int tagId = pInput.readUnsignedShort();
short type = pInput.readShort(); short type = pInput.readShort();
// This isn't really an entry, and the directory entry count was wrong OR bad data...
if (tagId == 0 && type == 0) {
return null;
}
int count = pInput.readInt(); // Number of values int count = pInput.readInt(); // Number of values
// It's probably a spec violation to have count 0, but we'll be lenient about it // It's probably a spec violation to have count 0, but we'll be lenient about it
@ -237,15 +234,16 @@ public final class EXIFReader extends MetadataReader {
} }
if (type <= 0 || type > 13) { if (type <= 0 || type > 13) {
pInput.skipBytes(4); // read Value
// Invalid tag, this is just for debugging // Invalid tag, this is just for debugging
long offset = pInput.getStreamPosition() - 8l; long offset = pInput.getStreamPosition() - 12l;
if (DEBUG) { if (DEBUG) {
System.err.printf("Bad EXIF data @%08x\n", pInput.getStreamPosition()); System.err.printf("Bad EXIF data @%08x\n", pInput.getStreamPosition());
System.err.println("tagId: " + tagId + (tagId <= 0 ? " (INVALID)" : "")); System.err.println("tagId: " + tagId + (tagId <= 0 ? " (INVALID)" : ""));
System.err.println("type: " + type + " (INVALID)"); System.err.println("type: " + type + " (INVALID)");
System.err.println("count: " + count); System.err.println("count: " + count);
}
pInput.mark(); pInput.mark();
pInput.seek(offset); pInput.seek(offset);
@ -262,7 +260,7 @@ public final class EXIFReader extends MetadataReader {
finally { finally {
pInput.reset(); pInput.reset();
} }
}
return null; return null;
} }
@ -510,7 +508,8 @@ public final class EXIFReader extends MetadataReader {
////////////////////// //////////////////////
// TODO: Stream based hex dump util? // TODO: Stream based hex dump util?
public static class HexDump { public static class HexDump {
private HexDump() {} private HexDump() {
}
private static final int WIDTH = 32; private static final int WIDTH = 32;

View File

@ -279,10 +279,17 @@ public class EXIFReaderTest extends MetadataReaderAbstractTest {
@Test @Test
public void testReadExifWithMissingEOFMarker() throws IOException { public void testReadExifWithMissingEOFMarker() throws IOException {
ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/noeof.tif")); try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/noeof.tif"))) {
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream); CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
assertEquals(15, directory.size()); assertEquals(15, directory.size());
assertEquals(1, directory.directoryCount()); assertEquals(1, directory.directoryCount());
stream.close(); }
}
public void testReadExifWithEmptyTag() throws IOException {
try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/emptyexiftag.tif"))) {
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
assertEquals(3, directory.directoryCount());
}
} }
} }