Skip to content

Commit

Permalink
Dont discard return values from func floatToUnsignedFraction
Browse files Browse the repository at this point in the history
fixes oss-fuzz-369652657

Test: ./ultrahdr_enc_fuzzer <cluster-fuzz-test-vector>
  • Loading branch information
ram-mohan committed Sep 29, 2024
1 parent 57247bf commit 43f62c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
31 changes: 23 additions & 8 deletions lib/src/gainmapmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,45 @@ uhdr_error_info_t uhdr_gainmap_metadata_frac::gainmapMetadataFloatToFraction(
to->backwardDirection = false;
to->useBaseColorSpace = true;

floatToUnsignedFraction(from->max_content_boost, &to->gainMapMaxN[0], &to->gainMapMaxD[0]);
#define CONVERT_FLT_TO_UNSIGNED_FRACTION(flt, numerator, denominator) \
if (!floatToUnsignedFraction(flt, numerator, denominator)) { \
uhdr_error_info_t status; \
status.error_code = UHDR_CODEC_INVALID_PARAM; \
status.has_detail = 1; \
snprintf(status.detail, sizeof status.detail, \
"encountered error while representing float %f as a rational number (p/q form) ", \
flt); \
return status; \
}

CONVERT_FLT_TO_UNSIGNED_FRACTION(from->max_content_boost, &to->gainMapMaxN[0],
&to->gainMapMaxD[0])
to->gainMapMaxN[2] = to->gainMapMaxN[1] = to->gainMapMaxN[0];
to->gainMapMaxD[2] = to->gainMapMaxD[1] = to->gainMapMaxD[0];

floatToUnsignedFraction(from->min_content_boost, &to->gainMapMinN[0], &to->gainMapMinD[0]);
CONVERT_FLT_TO_UNSIGNED_FRACTION(from->min_content_boost, &to->gainMapMinN[0],
&to->gainMapMinD[0]);
to->gainMapMinN[2] = to->gainMapMinN[1] = to->gainMapMinN[0];
to->gainMapMinD[2] = to->gainMapMinD[1] = to->gainMapMinD[0];

floatToUnsignedFraction(from->gamma, &to->gainMapGammaN[0], &to->gainMapGammaD[0]);
CONVERT_FLT_TO_UNSIGNED_FRACTION(from->gamma, &to->gainMapGammaN[0], &to->gainMapGammaD[0]);
to->gainMapGammaN[2] = to->gainMapGammaN[1] = to->gainMapGammaN[0];
to->gainMapGammaD[2] = to->gainMapGammaD[1] = to->gainMapGammaD[0];

floatToUnsignedFraction(from->offset_sdr, &to->baseOffsetN[0], &to->baseOffsetD[0]);
CONVERT_FLT_TO_UNSIGNED_FRACTION(from->offset_sdr, &to->baseOffsetN[0], &to->baseOffsetD[0]);
to->baseOffsetN[2] = to->baseOffsetN[1] = to->baseOffsetN[0];
to->baseOffsetD[2] = to->baseOffsetD[1] = to->baseOffsetD[0];

floatToUnsignedFraction(from->offset_hdr, &to->alternateOffsetN[0], &to->alternateOffsetD[0]);
CONVERT_FLT_TO_UNSIGNED_FRACTION(from->offset_hdr, &to->alternateOffsetN[0],
&to->alternateOffsetD[0]);
to->alternateOffsetN[2] = to->alternateOffsetN[1] = to->alternateOffsetN[0];
to->alternateOffsetD[2] = to->alternateOffsetD[1] = to->alternateOffsetD[0];

floatToUnsignedFraction(from->hdr_capacity_min, &to->baseHdrHeadroomN, &to->baseHdrHeadroomD);
CONVERT_FLT_TO_UNSIGNED_FRACTION(from->hdr_capacity_min, &to->baseHdrHeadroomN,
&to->baseHdrHeadroomD);

floatToUnsignedFraction(from->hdr_capacity_max, &to->alternateHdrHeadroomN,
&to->alternateHdrHeadroomD);
CONVERT_FLT_TO_UNSIGNED_FRACTION(from->hdr_capacity_max, &to->alternateHdrHeadroomN,
&to->alternateHdrHeadroomD);

return g_no_error;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/ultrahdr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,13 @@ uhdr_error_info_t uhdr_enc_set_gainmap_image(uhdr_codec_private_t* enc,
snprintf(status.detail, sizeof status.detail,
"received bad value for content boost min %f > max %f", metadata->min_content_boost,
metadata->max_content_boost);
} else if (metadata->min_content_boost < 0) {
status.error_code = UHDR_CODEC_INVALID_PARAM;
status.has_detail = 1;
snprintf(status.detail, sizeof status.detail,
"received bad value for min boost. min boost %f is less than 0",
metadata->min_content_boost);
return status;
} else if (metadata->gamma <= 0.0f) {
status.error_code = UHDR_CODEC_INVALID_PARAM;
status.has_detail = 1;
Expand Down

0 comments on commit 43f62c8

Please sign in to comment.