Skip to content

Free the frame buffer when dcm_frame_create() rejects it - #122

Open
ahkarl13 wants to merge 1 commit into
ImagingDataCommons:mainfrom
ahkarl13:pr/frame-leak
Open

Free the frame buffer when dcm_frame_create() rejects it#122
ahkarl13 wants to merge 1 commit into
ImagingDataCommons:mainfrom
ahkarl13:pr/frame-leak

Conversation

@ahkarl13

Copy link
Copy Markdown

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant