mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 03:55:28 -04:00
#291 Test case for added leniency for TIFF structures with pointers to data beyond EOF.
This commit is contained in:
parent
b12084c14c
commit
2f836de500
@ -37,8 +37,11 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
@ -286,10 +289,34 @@ public class EXIFReaderTest extends MetadataReaderAbstractTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadExifWithEmptyTag() throws IOException {
|
public void testReadExifWithEmptyTag() throws IOException {
|
||||||
try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/emptyexiftag.tif"))) {
|
try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/emptyexiftag.tif"))) {
|
||||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||||
assertEquals(3, directory.directoryCount());
|
assertEquals(3, directory.directoryCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadValueBeyondEOF() throws IOException {
|
||||||
|
ArrayList<Entry> entries = new ArrayList<>();
|
||||||
|
entries.add(new EXIFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, 1, TIFF.TYPE_SHORT));
|
||||||
|
entries.add(new EXIFEntry(TIFF.TAG_IMAGE_WIDTH, 10, TIFF.TYPE_SHORT));
|
||||||
|
entries.add(new EXIFEntry(TIFF.TAG_IMAGE_HEIGHT, 10, TIFF.TYPE_SHORT));
|
||||||
|
entries.add(new EXIFEntry(32934, new byte[10], TIFF.TYPE_UNDEFINED));
|
||||||
|
entries.add(new EXIFEntry(32935, 42, TIFF.TYPE_LONG));
|
||||||
|
|
||||||
|
try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/exif/value-beyond-eof.tif"))) {
|
||||||
|
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
|
||||||
|
assertEquals(1, directory.directoryCount());
|
||||||
|
assertEquals(5, directory.size());
|
||||||
|
|
||||||
|
assertEquals(1, directory.getEntryById(TIFF.TAG_PHOTOMETRIC_INTERPRETATION).getValue());
|
||||||
|
assertEquals(10, directory.getEntryById(TIFF.TAG_IMAGE_WIDTH).getValue());
|
||||||
|
assertEquals(10, directory.getEntryById(TIFF.TAG_IMAGE_HEIGHT).getValue());
|
||||||
|
assertEquals(42L, directory.getEntryById(32935).getValue());
|
||||||
|
// NOTE: Assumes current implementation, could possibly change in the future.
|
||||||
|
assertTrue(directory.getEntryById(32934).getValue() instanceof EOFException);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user