Skip to content

Commit

Permalink
Ensure incoming NCLX enum values are cast before use
Browse files Browse the repository at this point in the history
Brings aom and dav1d decoders in line with de265
  • Loading branch information
lovell authored and farindk committed Dec 20, 2022
1 parent 521d5c2 commit 1abe388
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions libheif/plugins/heif_decoder_aom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ struct heif_error aom_decode_image(void* decoder_raw, struct heif_image** out_im

heif_color_profile_nclx nclx;
nclx.version = 1;
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_color_primaries(&nclx, img->cp), { heif_image_release(heif_img); });
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_transfer_characteristics(&nclx, img->tc), { heif_image_release(heif_img); });
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_matrix_coefficients(&nclx, img->mc), { heif_image_release(heif_img); });
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_color_primaries(&nclx, static_cast<uint16_t>(img->cp)), { heif_image_release(heif_img); });
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_transfer_characteristics(&nclx, static_cast<uint16_t>(img->tc)), { heif_image_release(heif_img); });
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_matrix_coefficients(&nclx, static_cast<uint16_t>(img->mc)), { heif_image_release(heif_img); });
nclx.full_range_flag = (img->range == AOM_CR_FULL_RANGE);
heif_image_set_nclx_color_profile(heif_img, &nclx);

Expand Down
6 changes: 3 additions & 3 deletions libheif/plugins/heif_decoder_dav1d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ struct heif_error dav1d_decode_image(void* decoder_raw, struct heif_image** out_
// --- read nclx parameters from decoded AV1 bitstream

heif_color_profile_nclx nclx;
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_color_primaries(&nclx, frame.seq_hdr->pri), {});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_transfer_characteristics(&nclx, frame.seq_hdr->trc), {});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_matrix_coefficients(&nclx, frame.seq_hdr->mtrx), {});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_color_primaries(&nclx, static_cast<uint16_t>(frame.seq_hdr->pri)), {});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_transfer_characteristics(&nclx, static_cast<uint16_t>(frame.seq_hdr->trc)), {});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, heif_img, heif_nclx_color_profile_set_matrix_coefficients(&nclx, static_cast<uint16_t>(frame.seq_hdr->mtrx)), {});
nclx.full_range_flag = (frame.seq_hdr->color_range != 0);
heif_image_set_nclx_color_profile(heif_img, &nclx);

Expand Down
6 changes: 3 additions & 3 deletions libheif/plugins/heif_decoder_libde265.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ static struct heif_error libde265_v1_decode_image(void* decoder_raw,

struct heif_color_profile_nclx* nclx = heif_nclx_color_profile_alloc();
#if LIBDE265_NUMERIC_VERSION >= 0x01000700
HEIF_WARN_OR_FAIL(decoder->strict_decoding, *out_img, heif_nclx_color_profile_set_color_primaries(nclx, (uint16_t)de265_get_image_colour_primaries(image)), { heif_nclx_color_profile_free(nclx);});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, *out_img, heif_nclx_color_profile_set_transfer_characteristics(nclx, (uint16_t)de265_get_image_transfer_characteristics(image)), { heif_nclx_color_profile_free(nclx);});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, *out_img, heif_nclx_color_profile_set_matrix_coefficients(nclx, (uint16_t)de265_get_image_matrix_coefficients(image)), { heif_nclx_color_profile_free(nclx);});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, *out_img, heif_nclx_color_profile_set_color_primaries(nclx, static_cast<uint16_t>(de265_get_image_colour_primaries(image))), { heif_nclx_color_profile_free(nclx);});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, *out_img, heif_nclx_color_profile_set_transfer_characteristics(nclx, static_cast<uint16_t>(de265_get_image_transfer_characteristics(image))), { heif_nclx_color_profile_free(nclx);});
HEIF_WARN_OR_FAIL(decoder->strict_decoding, *out_img, heif_nclx_color_profile_set_matrix_coefficients(nclx, static_cast<uint16_t>(de265_get_image_matrix_coefficients(image))), { heif_nclx_color_profile_free(nclx);});
nclx->full_range_flag = (bool)de265_get_image_full_range_flag(image);
#endif
heif_image_set_nclx_color_profile(*out_img, nclx);
Expand Down

0 comments on commit 1abe388

Please sign in to comment.