-
-
Notifications
You must be signed in to change notification settings - Fork 888
V4: Prevent negative allocation attempt for huge TIFF files #3003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR prevents negative allocation attempts when processing huge TIFF files with uncompressed strips larger than Int32.MaxValue bytes. The changes address overflow issues in buffer size calculations and implement a fallback mechanism for handling extremely large strips.
Key Changes:
- Modified
CalculateStripBufferSizeto returnulonginstead ofintto prevent overflow in size calculations - Added validation checks to prevent allocating buffers larger than Int32.MaxValue
- Implemented row-by-row processing for uncompressed TIFF files with extremely large strips
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| TiffDecoderCore.cs | Changed strip buffer size calculation to use ulong, added validation for Int32.MaxValue limits, and implemented fallback row-by-row processing for huge uncompressed strips |
| TiffBaseDecompressor.cs | Renamed parameters for clarity and updated validation to check count against int.MaxValue instead of long.MaxValue |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // This should never happen, but we check just to be sure. | ||
| if (bytesPerRowU > int.MaxValue) | ||
| { | ||
| TiffThrowHelper.ThrowNotSupported("Strips larger than Int32.MaxValue bytes are not supported for compressed images."); |
Copilot
AI
Oct 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message states 'compressed images' but this check is within a code path specifically handling uncompressed images (NoneTiffCompression). The message should say 'uncompressed images' or 'rows' to accurately reflect the context.
| TiffThrowHelper.ThrowNotSupported("Strips larger than Int32.MaxValue bytes are not supported for compressed images."); | |
| TiffThrowHelper.ThrowNotSupported("Strips larger than Int32.MaxValue bytes are not supported for uncompressed images."); |
| int stripHeight = stripIndex < stripOffsets.Length - 1 || height % rowsPerStrip == 0 | ||
| ? rowsPerStrip | ||
| : height % rowsPerStrip; |
Copilot
AI
Oct 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This strip height calculation logic is duplicated from the standard path below (around line 603). Consider extracting this into a helper method to reduce code duplication and improve maintainability.
Prerequisites
Description
Fixes #2959
Note: Image from issue was tested locally. It's far too large at 14.1GB to add to references.