Fix CCITT decompressor bounds checks and error handling
Merged
JI
2mo ago+86+86+01234567890123456789-16-16-01234567890123456789
Prerequisites
- I have written a descriptive pull-request title
- I have verified that there are no overlapping pull-requests open
- I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:.
- I have provided test coverage for my change (where applicable)
Description
This pull request strengthens the handling of CCITT (fax) TIFF decompression by adding strict validation to prevent writing more pixels than the image width, especially in tiled images. It also introduces targeted regression tests to ensure these checks work as intended. The changes improve both the robustness and reliability of TIFF decoding.
TIFF CCITT Decompression Robustness:
- Added checks in
ModifiedHuffmanTiffCompression,T4TiffCompression, andT6TiffCompressionto throw anImageFormatExceptionif a decoded run exceeds the image row width, preventing buffer overruns and ensuring data integrity. [1] [2] [3] [4] [5] - Updated error messages for consistency and clarity in
T4BitReadermethods. [1] [2]
Tiled TIFF Support Improvements:
- Modified the TIFF decompressor factory and decoder to correctly handle tiled images by passing the tile width to fax decompressors, ensuring proper row width validation during decompression. [1] [2] [3]
Testing and Regression Coverage:
- Added new regression tests in
CcittTiffCompressionTests.csto verify that oversized runs in both strip-based and tiled CCITT TIFF images throw the correctImageFormatException. These tests use compressed TIFF samples to keep the test codebase small and efficient.