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

Fix gain map memory leak and null ptr dereference #1883

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions apps/shared/avifjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,12 @@ static avifBool avifJPEGReadInternal(FILE * f,
#if defined(AVIF_ENABLE_EXPERIMENTAL_JPEG_GAIN_MAP_CONVERSION)
// The primary XMP block (for the main image) must contain a node with an hdrgm:Version field if and only if a gain map is present.
if (!ignoreGainMap && avifJPEGHasGainMapXMPNode(avif->xmp.data, avif->xmp.size)) {
// Ignore the return value: continue even if we fail to find/parse/decode the gain map.
avifGainMap * gainMap = avifGainMapCreate();
if (gainMap == NULL) {
fprintf(stderr, "Creating gain map failed: out of memory\n");
goto cleanup;
}
// Ignore the return value: continue even if we fail to find/parse/decode the gain map.
if (avifJPEGExtractGainMapImage(f, &cinfo, gainMap, chromaDownsampling)) {
// Since jpeg doesn't provide this metadata, assume the values are the same as the base image
// with a PQ transfer curve.
Expand All @@ -1161,7 +1165,9 @@ static avifBool avifJPEGReadInternal(FILE * f,

if (avif->xmp.size > 0 && ignoreXMP) {
// Clear XMP in case we read it for something else (like gain map).
AVIF_CHECK(avifImageSetMetadataXMP(avif, NULL, 0) == AVIF_RESULT_OK);
if (avifImageSetMetadataXMP(avif, NULL, 0) != AVIF_RESULT_OK) {
assert(AVIF_FALSE);
}
}
#endif // AVIF_ENABLE_EXPERIMENTAL_JPEG_GAIN_MAP_CONVERSION
jpeg_finish_decompress(&cinfo);
Expand Down
1 change: 1 addition & 0 deletions src/avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ void avifGainMapDestroy(avifGainMap * gainMap)
if (gainMap->image) {
avifImageDestroy(gainMap->image);
}
avifRWDataFree(&gainMap->altICC);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh, actually this should be moved to avifGainMapDestroy() and the call below should be avifGainMapDestroy() as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I misread the github diff this is actually what you're doing -_- nevermind!

avifFree(gainMap);
}
#endif // AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP
Loading