Skip to content
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

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ static avifMeta * avifMetaCreate()

static void avifMetaDestroy(avifMeta * meta)
{
if (meta == NULL) {
Copy link
Collaborator

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).

Copy link
Collaborator Author

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.

return;
}
Copy link
Collaborator

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);
    }

Copy link
Collaborator Author

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);
    }

Done


for (uint32_t i = 0; i < meta->items.count; ++i) {
avifDecoderItem * item = meta->items.item[i];
avifArrayDestroy(&item->properties);
Expand Down
Loading