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.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -123,7 +123,8 @@ static inline unsigned get_variable_bits(GetBitContext *gb, int n) · 122 unmodified lines | ||
| 123 | 123 | if (VAR < MIN || VAR > MAX) { \ |
| 124 | 124 | av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: " \ |
| 125 | 125 | #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR); \ |
| 126 | − goto fail; \ | |
| 126 | + ff_dovi_ctx_unref(s); \ | |
| 127 | + return AVERROR_INVALIDDATA; \ | |
| 127 | 128 | } \ |
| 128 | 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 | 176 | return 0; |
| 176 | − | |
| 177 | −fail: | |
| 178 | − return AVERROR_INVALIDDATA; | |
| 179 | 177 | } |
| 180 | 178 | |
| 181 | 179 | static 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 | 316 | uint8_t profile; |
| 319 | 317 | |
| 320 | 318 | if (rpu_size < 5) |
| 321 | − goto fail; | |
| 319 | + return AVERROR_INVALIDDATA; | |
| 322 | 320 | |
| 323 | 321 | /* Container */ |
| 324 | 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 | 372 | if (!rpu_size || rpu[rpu_size - 1] != 0x80) |
| 375 | − goto fail; | |
| 373 | + return AVERROR_INVALIDDATA; | |
| 376 | 374 | |
| 377 | 375 | if (err_recognition & AV_EF_CRCCHECK) { |
| 378 | 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 | 378 | if (crc) { |
| 381 | 379 | av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc); |
| 382 | 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 | 449 | profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr); |
| 452 | 450 | if (profile == 5 && use_nlq) { |
| 453 | 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 | 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 | 464 | * out as this corner case is not hit in practice */ |
| 466 | 465 | av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n", |
| 467 | 466 | prev_vdr_rpu_id); |
| 468 | − goto fail; | |
| 467 | + ff_dovi_ctx_unref(s); | |
| 468 | + return AVERROR_INVALIDDATA; | |
| 469 | 469 | } |
| 470 | 470 | s->mapping = s->vdr[prev_vdr_rpu_id]; |
| 471 | 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 | 474 | VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID); |
| 475 | 475 | if (!s->vdr[vdr_rpu_id]) { |
| 476 | 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 | 479 | return AVERROR(ENOMEM); |
| 480 | + } | |
| 479 | 481 | } |
| 480 | 482 | |
| 481 | 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 | 651 | return 0; |
| 650 | − | |
| 651 | −fail: | |
| 652 | − ff_dovi_ctx_unref(s); /* don't leak potentially invalid state */ | |
| 653 | − return AVERROR_INVALIDDATA; | |
| 654 | 652 | } |