Reject truncated JPEG image buffers - #38
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the robustness of JPEG decoding in the
imdecodefunction by adding explicit validation to detect truncated or malformed JPEG files before attempting to decode them. It also introduces comprehensive tests to ensure truncated or manipulated JPEGs are correctly rejected and that trailing bytes after a valid JPEG are tolerated.JPEG validation improvements:
validate_jpeg_completefunction to theimdecodeimplementation incv_compat.rsthat parses JPEG markers to ensure the image is complete and not truncated before decoding. This function checks for the presence and correct order of JPEG markers, including the end-of-image marker, and rejects files with missing or misplaced markers. [1] [2]Testing enhancements:
tests.rsto verify that truncated JPEGs are rejected, JPEGs with marker bytes in metadata are not incorrectly accepted as complete, and valid JPEGs with trailing non-image data are still accepted. [1] [2]