Replace remaining sprintf() with snprintf()#9476
Open
myagmartseren wants to merge 2 commits intopython-pillow:mainfrom
Open
Replace remaining sprintf() with snprintf()#9476myagmartseren wants to merge 2 commits intopython-pillow:mainfrom
myagmartseren wants to merge 2 commits intopython-pillow:mainfrom
Conversation
Replace unsafe sprintf() calls with bounds-checked snprintf() in: - src/libImaging/QuantPngQuant.c (version string) - src/libImaging/JpegEncode.c (version string) - src/_webp.c (error messages and version string, 4 call sites) This is consistent with the fix applied in CVE-2024-28219 which addressed the same class of vulnerability in font rendering code. Security: CWE-120 (Buffer Copy without Checking Size of Input)
for more information, see https://pre-commit.ci
|
Thanks for running a scanner -- note that we have a security policy here: https://github.com/python-pillow/Pillow/blob/main/.github/SECURITY.md that does not include posting security sensitive issues in public. Also note that in this case, some of the items that are running through sprintf are statically determined at compile time and have no way of being attacker controlled. |
Member
|
This does seem like a rather difficult exploit. If an attacker managed to change the value |
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.
Replace All Remaining sprintf() with snprintf()
Summary
Multiple C source files still use
sprintf()without bounds checking — the same class of vulnerability fixed in CVE-2024-28219. This PR replaces all remaining instances withsnprintf().Affected Files (6 call sites)
src/libImaging/QuantPngQuant.csprintf(version, "%d.%d.%d", ...)src/libImaging/JpegEncode.csprintf(version, "%d.%d", ...)src/_webp.csprintf(message, "could not assemble chunks: %s", ...)src/_webp.csprintf(message, "could not set %.4s chunk: %s", ...)src/_webp.csprintf(message, ": Image size exceeds WebP limit...")src/_webp.csprintf(version, "%d.%d.%d", ...)Fix
All
sprintf(buf, ...)→snprintf(buf, sizeof(buf), ...)Classification