Use delete[] to free new[]-allocated buffer in decodeJPEGIntoSurface OOM path#2575
Open
iurisilvio wants to merge 1 commit into
Open
Use delete[] to free new[]-allocated buffer in decodeJPEGIntoSurface OOM path#2575iurisilvio wants to merge 1 commit into
iurisilvio wants to merge 1 commit into
Conversation
`Image::decodeJPEGIntoSurface` allocates a buffer with `new uint8_t[]` and freed it with `free()` on the OOM error path — undefined behavior in C++ (`new[]` and `free()` may use different allocators, and even when they share one they may have different bookkeeping for the array size header). Every other deallocation of `new uint8_t[]` buffers in Image.cc uses `delete[]` correctly; this is the only outlier. Caught by `g++ -Wmismatched-new-delete`. Fixes Automattic#2573
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.
Fixes #2573.
Image::decodeJPEGIntoSurfaceallocates a buffer withnew uint8_t[]and frees it withfree()on the OOM error path — undefined behavior in C++ (new[]andfree()may use different allocators, and even when they share one they may have different bookkeeping for the array size header).Every other deallocation of
new uint8_t[]buffers inImage.cc(lines 710, 898, 901, 991) already usesdelete[]correctly; this is the only outlier. Caught byg++ -Wmismatched-new-delete:The triggering condition (the second
new uint8_t[]returningnullptrafter the first succeeds) is unlikely in practice, but the bug is real and the fix is one character.