While reading a TIFF image with LZW compression, we start reading the content of LZW strip data without veryfing whether we actually have the needed bytes. This ends up throwing ArrayIndexOutOfBoundsException, in case of ImageIO.read() we wrap this ArrayIndexOutOfBoundsException into IIOException but if we use the reader directly application will see the AIOOBE.
TIFF 6.0 mentions that each LZW strip should contain clear & eoi code: https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf#page=61. So the fix now checks these minimal requirements before reading the strip data array. TIFF spec doesn't mandate that strip byte count should be positive. So we actually allow 0 strip byte count value and this causes issues in other compression types. Initially i tried restricting the byte count to be positive but these needs more analysis. So i have created [JDK-8396412](https://bugs.openjdk.org/browse/JDK-8396412). Testing is green with this update. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - Remove generic byteCount check - Update - Update test - Move byteCount check - Add test - Merge remote-tracking branch 'upstream/master' into 8394183 - Add LZW length checks Changes: https://git.openjdk.org/jdk/pull/33689/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=33689&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8394183 Stats: 90 lines in 2 files changed: 89 ins; 0 del; 1 mod Patch: https://git.openjdk.org/jdk/pull/33689.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/33689/head:pull/33689 PR: https://git.openjdk.org/jdk/pull/33689
