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

Showing the changes to libavcodec (1 of 1 file). Show all

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
123123 if (VAR < MIN || VAR > MAX) { \
124124 av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: " \
125125 #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR); \
126− goto fail; \
126+ ff_dovi_ctx_unref(s); \
127+ return AVERROR_INVALIDDATA; \
127128 } \
128129 } while (0)
129130
@@ -173,9 +174,6 @@ static int parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm) · 43 unmodified lines
173174 }
174175
175176 return 0;
176−
177−fail:
178− return AVERROR_INVALIDDATA;
179177 }
180178
181179 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
318316 uint8_t profile;
319317
320318 if (rpu_size < 5)
321− goto fail;
319+ return AVERROR_INVALIDDATA;
322320
323321 /* Container */
324322 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
372370 }
373371
374372 if (!rpu_size || rpu[rpu_size - 1] != 0x80)
375− goto fail;
373+ return AVERROR_INVALIDDATA;
376374
377375 if (err_recognition & AV_EF_CRCCHECK) {
378376 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
380378 if (crc) {
381379 av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);
382380 if (err_recognition & AV_EF_EXPLODE)
383− goto fail;
381+ return AVERROR_INVALIDDATA;
384382 }
385383 }
386384
@@ -451,7 +449,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 64 unmodified lines
451449 profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr);
452450 if (profile == 5 && use_nlq) {
453451 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;
455454 }
456455
457456 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
465464 * out as this corner case is not hit in practice */
466465 av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n",
467466 prev_vdr_rpu_id);
468− goto fail;
467+ ff_dovi_ctx_unref(s);
468+ return AVERROR_INVALIDDATA;
469469 }
470470 s->mapping = s->vdr[prev_vdr_rpu_id];
471471 } else {
@@ -474,8 +474,10 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 2 unmodified lines
474474 VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID);
475475 if (!s->vdr[vdr_rpu_id]) {
476476 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);
478479 return AVERROR(ENOMEM);
480+ }
479481 }
480482
481483 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
647649 }
648650
649651 return 0;
650−
651−fail:
652− ff_dovi_ctx_unref(s); /* don't leak potentially invalid state */
653− return AVERROR_INVALIDDATA;
654652 }

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