History

avcodec/dovi_rpudec: handle errors consistently

Only flush state when we started parsing data, otherwise just error out. Remove the 'fail' label to make this a bit less confusing to read.

Niklas Haas committed 2 years ago

Commit 90579fb1 parent 0a5ed911 file · +12 −14Browse files

Unified · Split

libavcodec/dovi_rpudec.c+12−14
@@ -123,7 +123,8 @@ static inline unsigned get_variable_bits(GetBitContext *gb, int n) · 122 unmodified lines
123 if (VAR < MIN || VAR > MAX) { \123 if (VAR < MIN || VAR > MAX) { \
124 av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: " \124 av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: " \
125 #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR); \125 #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR); \
126 goto fail; \126 ff_dovi_ctx_unref(s); \
127 return AVERROR_INVALIDDATA; \
127 } \128 } \
128 } while (0)129 } while (0)
129 130
@@ -173,9 +174,6 @@ static int parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm) · 43 unmodified lines
173 }174 }
174 175
175 return 0;176 return 0;
176
177fail:
178 return AVERROR_INVALIDDATA;
179}177}
180 178
181static AVCIExy get_cie_xy(GetBitContext *gb)179static AVCIExy get_cie_xy(GetBitContext *gb)
@@ -318,7 +316,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 136 unmodified lines
318 uint8_t profile;316 uint8_t profile;
319 317
320 if (rpu_size < 5)318 if (rpu_size < 5)
321 goto fail;319 return AVERROR_INVALIDDATA;
322 320
323 /* Container */321 /* Container */
324 if (s->cfg.dv_profile == 10 /* dav1.10 */) {322 if (s->cfg.dv_profile == 10 /* dav1.10 */) {
@@ -372,7 +370,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 47 unmodified lines
372 }370 }
373 371
374 if (!rpu_size || rpu[rpu_size - 1] != 0x80)372 if (!rpu_size || rpu[rpu_size - 1] != 0x80)
375 goto fail;373 return AVERROR_INVALIDDATA;
376 374
377 if (err_recognition & AV_EF_CRCCHECK) {375 if (err_recognition & AV_EF_CRCCHECK) {
378 uint32_t crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE),376 uint32_t crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE),
@@ -380,7 +378,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 1 unmodified line
380 if (crc) {378 if (crc) {
381 av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);379 av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);
382 if (err_recognition & AV_EF_EXPLODE)380 if (err_recognition & AV_EF_EXPLODE)
383 goto fail;381 return AVERROR_INVALIDDATA;
384 }382 }
385 }383 }
386 384
@@ -451,7 +449,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 64 unmodified lines
451 profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr);449 profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr);
452 if (profile == 5 && use_nlq) {450 if (profile == 5 && use_nlq) {
453 av_log(s->logctx, AV_LOG_ERROR, "Profile 5 RPUs should not use NLQ\n");451 av_log(s->logctx, AV_LOG_ERROR, "Profile 5 RPUs should not use NLQ\n");
454 goto fail;452 ff_dovi_ctx_unref(s);
453 return AVERROR_INVALIDDATA;
455 }454 }
456 455
457 if (use_prev_vdr_rpu) {456 if (use_prev_vdr_rpu) {
@@ -465,7 +464,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 7 unmodified lines
465 * out as this corner case is not hit in practice */464 * out as this corner case is not hit in practice */
466 av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n",465 av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n",
467 prev_vdr_rpu_id);466 prev_vdr_rpu_id);
468 goto fail;467 ff_dovi_ctx_unref(s);
468 return AVERROR_INVALIDDATA;
469 }469 }
470 s->mapping = s->vdr[prev_vdr_rpu_id];470 s->mapping = s->vdr[prev_vdr_rpu_id];
471 } else {471 } else {
@@ -474,8 +474,10 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 2 unmodified lines
474 VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID);474 VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID);
475 if (!s->vdr[vdr_rpu_id]) {475 if (!s->vdr[vdr_rpu_id]) {
476 s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping));476 s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping));
477 if (!s->vdr[vdr_rpu_id])477 if (!s->vdr[vdr_rpu_id]) {
478 ff_dovi_ctx_unref(s);
478 return AVERROR(ENOMEM);479 return AVERROR(ENOMEM);
480 }
479 }481 }
480 482
481 s->mapping = mapping = s->vdr[vdr_rpu_id];483 s->mapping = mapping = s->vdr[vdr_rpu_id];
@@ -647,8 +649,4 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 165 unmodified lines
647 }649 }
648 650
649 return 0;651 return 0;
650
651fail:
652 ff_dovi_ctx_unref(s); /* don't leak potentially invalid state */
653 return AVERROR_INVALIDDATA;
654}652}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t