Skip to content

Commit

Permalink
Fix possible null pointer dereference and unintended integer division
Browse files Browse the repository at this point in the history
  • Loading branch information
maryla-uc committed Oct 7, 2024
1 parent 4932ace commit 9829987
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/avifgainmaputil/tonemap_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ avifResult TonemapCommand::Run() {
static_cast<float>(image->gainMap->baseHdrHeadroom.n) /
image->gainMap->baseHdrHeadroom.d;
const float alternate_hdr_hreadroom =
static_cast<float>(image->gainMap->alternateHdrHeadroom.n /
image->gainMap->alternateHdrHeadroom.d);
static_cast<float>(image->gainMap->alternateHdrHeadroom.n) /
image->gainMap->alternateHdrHeadroom.d;
// We are either tone mapping to the base image (i.e. leaving it as is),
// or tone mapping to the alternate image (i.e. fully applying the gain map),
// or tone mapping in between (partially applying the gain map).
Expand Down
3 changes: 1 addition & 2 deletions src/gainmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ avifResult avifRGBImageApplyGainMap(const avifRGBImage * baseImage,
{
avifDiagnosticsClearError(diag);

AVIF_CHECKRES(avifGainMapValidateMetadata(gainMap, diag));

if (hdrHeadroom < 0.0f) {
avifDiagnosticsPrintf(diag, "hdrHeadroom should be >= 0, got %f", hdrHeadroom);
return AVIF_RESULT_INVALID_ARGUMENT;
Expand All @@ -87,6 +85,7 @@ avifResult avifRGBImageApplyGainMap(const avifRGBImage * baseImage,
avifDiagnosticsPrintf(diag, "NULL input image");
return AVIF_RESULT_INVALID_ARGUMENT;
}
AVIF_CHECKRES(avifGainMapValidateMetadata(gainMap, diag));

const uint32_t width = baseImage->width;
const uint32_t height = baseImage->height;
Expand Down

0 comments on commit 9829987

Please sign in to comment.