-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avifMetaDestroy: check meta pointer before accessing #2065
Conversation
fixes a NULL dereference should avifMetaCreate() fail and avifDecoderDataDestroy() is called to clean up. Found by Nallocfuzz (https://github.com/catenacyber/nallocfuzz).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. I suggest two changes.
src/read.c
Outdated
@@ -760,6 +760,10 @@ static avifMeta * avifMetaCreate() | |||
|
|||
static void avifMetaDestroy(avifMeta * meta) | |||
{ | |||
if (meta == NULL) { | |||
return; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The current style in src/read.c is to have the caller handle this. For example, see the second avifMetaDestroy()
call in avifDecoderDataDestroy()
:
static void avifDecoderDataDestroy(avifDecoderData * data)
{
avifMetaDestroy(data->meta);
for (uint32_t i = 0; i < data->tracks.count; ++i) {
avifTrack * track = &data->tracks.track[i];
if (track->sampleTable) {
avifSampleTableDestroy(track->sampleTable);
}
if (track->meta) {
avifMetaDestroy(track->meta);
}
}
avifArrayDestroy(&data->tracks);
avifDecoderDataClearTiles(data);
avifArrayDestroy(&data->tiles);
avifFree(data);
}
So I suggest adding a similar null pointer check to the first avifMetaDestroy()
call in avifDecoderDataDestroy()
.
if (data->meta) {
avifMetaDestroy(data->meta);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The current style in src/read.c is to have the caller handle this. For example, see the second
avifMetaDestroy()
call inavifDecoderDataDestroy()
:static void avifDecoderDataDestroy(avifDecoderData * data) { avifMetaDestroy(data->meta); for (uint32_t i = 0; i < data->tracks.count; ++i) { avifTrack * track = &data->tracks.track[i]; if (track->sampleTable) { avifSampleTableDestroy(track->sampleTable); } if (track->meta) { avifMetaDestroy(track->meta); } } avifArrayDestroy(&data->tracks); avifDecoderDataClearTiles(data); avifArrayDestroy(&data->tiles); avifFree(data); }
So I suggest adding a similar null pointer check to the first
avifMetaDestroy()
call inavifDecoderDataDestroy()
.if (data->meta) { avifMetaDestroy(data->meta); }
Done
src/read.c
Outdated
@@ -760,6 +760,10 @@ static avifMeta * avifMetaCreate() | |||
|
|||
static void avifMetaDestroy(avifMeta * meta) | |||
{ | |||
if (meta == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message should also acknowledge the person who ran nallocfuzz and reported this bug to us (Philippe Antoine).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message should also acknowledge the person who ran nallocfuzz and reported this bug to us (Philippe Antoine).
Found by Nallocfuzz (https://github.com/catenacyber/nallocfuzz).
This was the format I used in other projects, that was suggested by Philippe. I can add his name though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
fixes a NULL dereference should avifMetaCreate() fail and
avifDecoderDataDestroy() is called to clean up.
Found by Nallocfuzz (https://github.com/catenacyber/nallocfuzz).