Free the frame buffer when dcm_frame_create() rejects it - #122
Open
ahkarl13 wants to merge 1 commit into
Open
Conversation
dcm_frame_create() validates the pixel description before it takes
ownership of the data pointer, and returns NULL on an empty frame, a
bad BitsAllocated, PixelRepresentation, or PlanarConfiguration, or an
allocation failure. dcm_filehandle_read_frame() ignored that and
returned straight away, so the decoded frame buffer was never freed.
The leak is the size of the frame data in the file, not a fixed
overhead, and it repeats on every call:
386 byte file -> 8 byte(s) leaked in 1 allocation(s)
8 MB file -> 8388608 byte(s) leaked in 1 allocation(s)
Both from the same input with PixelRepresentation out of range; a
service reading frames from files it did not produce leaks the whole
frame each time.
Found by the libFuzzer target, replaying a 90 minute run's corpus with
LeakSanitizer enabled.
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.
dcm_frame_create() validates the pixel description before it takes ownership of the data pointer, and returns NULL on an empty frame or a bad BitsAllocated, PixelRepresentation or PlanarConfiguration. dcm_filehandle_read_frame() returned straight away without freeing what it had already decoded.
The leak is the size of the frame data, not a fixed overhead, and it repeats on every call:
386 byte file -> 8 byte(s) leaked in 1 allocation(s)
8 MB file -> 8388608 byte(s) leaked in 1 allocation(s)
Same input both times, with PixelRepresentation out of range. A service reading frames from files it didn't produce leaks the whole frame each time.