tballison commented on code in PR #3130:
URL: https://github.com/apache/tika/pull/3130#discussion_r3936782264
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/detect/image/RawTiffDetectorTest.java:
##########
@@ -224,6 +225,49 @@ public void testTruncatedPrefixIsHarmless() {
}
}
+ /**
+ * A BigTIFF directory offset near {@code Long.MAX_VALUE}: adding the entry
+ * count to it wraps negative, and a negative end must not read as "already
+ * in the prefix". The three pointer sources (this header field, a SubIFDs
+ * array, the follower below) all reach the same bounds check.
+ */
+ @ParameterizedTest
+ @ValueSource(longs = {Long.MAX_VALUE, Long.MAX_VALUE - 7, Long.MAX_VALUE -
8,
+ 0x100000000L, 1024L * 1024L + 1})
+ public void testDirectoryOffsetBeyondTheFileIsRejected(long firstIfd)
throws Exception {
+ byte[] tiff = bigTiffHeader(firstIfd);
+ assertEquals(MediaType.OCTET_STREAM, RawTiffDetector.detect(tiff,
tiff.length));
+ try (TikaInputStream tis = TikaInputStream.get(tiff)) {
+ assertEquals(MediaType.OCTET_STREAM,
+ new RawTiffDetector().detect(tis, new Metadata(), new
ParseContext()));
+ }
+ }
+
+ /**
+ * The same offset as the follower of an otherwise good directory: the
+ * vendor the directory names still decides the type.
+ */
Review Comment:
Fair -- "the vendor the directory names" is a garden path. Reworded to spell
out both halves of what the test asserts:
```
/**
* The same offset as the follower of an otherwise good directory: the
* follower is skipped and the vendor named in the directory already read
* still decides the type.
*/
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]