Fix buffer overflow in fscan_pnm_token (pnm2png)#1
Closed
Fix buffer overflow in fscan_pnm_token (pnm2png)#1
Conversation
The fscan_pnm_token function in contrib/pngminus/pnm2png.c did not properly check for buffer boundaries while reading numeric tokens from PNM headers. This could lead to a buffer overflow when parsing very long lines, potentially causing denial-of-service behavior. This patch adds a length check to ensure that the token_buf array is not written beyond its allocated size. The buffer is now safely null-terminated and the maximum allowed characters are respected. This affects the pnm2png conversion utility only, and not the core libpng library.
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.
Summary
This PR fixes a buffer overflow vulnerability in the
fscan_pnm_tokenfunction incontrib/pngminus/pnm2png.c, which is used by thepnm2pngconversion tool.Vulnerability
The original implementation lacked bounds checking when reading tokens from the PNM header. If a header line (e.g., width or height) was excessively long, the function could write past the end of the token buffer, potentially causing a crash or denial of service.
Fix
The patch adds a check to ensure that the buffer is not overrun: