mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
#574 Fix for possible OOME in Exif metadata.
This commit is contained in:
+29
-12
@@ -30,6 +30,20 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.metadata.tiff;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.CompoundDirectory;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
@@ -38,18 +52,6 @@ import com.twelvemonkeys.imageio.metadata.exif.EXIF;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* TIFFReaderTest
|
||||
*
|
||||
@@ -348,6 +350,21 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadWithoutOOME() throws IOException {
|
||||
// This EXIF segment from a JPEG contains an Interop IFD, containing a weird value that could be interpreted
|
||||
// as a huge SLONG8 field (valid for BigTIFF only).
|
||||
// OutOfMemoryError would only happen if length of stream is not known (ie. reading from underlying stream).
|
||||
try (InputStream stream = getResource("/exif/exif-bad-interop-oome.bin").openStream()) {
|
||||
CompoundDirectory directory = (CompoundDirectory) createReader().read(new MemoryCacheImageInputStream(stream));
|
||||
assertEquals(2, directory.directoryCount());
|
||||
assertEquals(11, directory.getDirectory(0).size());
|
||||
assertEquals(6, directory.getDirectory(1).size());
|
||||
assertEquals("Picasa", directory.getDirectory(0).getEntryById(TIFF.TAG_SOFTWARE).getValue());
|
||||
assertEquals("2020:11:17 16:05:37", directory.getDirectory(0).getEntryById(TIFF.TAG_DATE_TIME).getValueAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 200)
|
||||
public void testReadCyclicExifWithoutLoopOrOOME() throws IOException {
|
||||
// This EXIF segment has an interesting bug...
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user