History

apv_decode: Discard invalid run codes earlier

Caught by ubsan - would cause an invalid shift in constructing the run value.

Mark Thompson committed 1 year ago

Commit 527d5ea1 parent 1753d411 file · +14 −0Browse files

Unified · Split

libavcodec/apv_entropy.c+14−0
@@ -278,6 +278,13 @@ int ff_apv_entropy_decode_block(int16_t *restrict coeff, · 277 unmodified lines
278278 bits = next_bits & 0xffff;
279279 // Determine code length.
280280 leading_zeroes = 15 - av_log2(bits);
281+ if (leading_zeroes >= 6) {
282+ // 6 zeroes implies run > 64, which is always invalid.
283+ av_log(state->log_ctx, AV_LOG_ERROR,
284+ "Out-of-range run value: %d leading zeroes.\n",
285+ leading_zeroes);
286+ return AVERROR_INVALIDDATA;
287+ }
281288 // Extract the low bits.
282289 low_bit_count = leading_zeroes;
283290 low_bit_shift = 16 - (1 + 2 * leading_zeroes);
@@ -443,6 +450,13 @@ int ff_apv_entropy_decode_block(int16_t *restrict coeff, · 159 unmodified lines
443450 bits = next_bits & 0xffff;
444451 // Determine code length.
445452 leading_zeroes = 15 - av_log2(bits);
453+ if (leading_zeroes >= 6) {
454+ // 6 zeroes implies run > 64, which is always invalid.
455+ av_log(state->log_ctx, AV_LOG_ERROR,
456+ "Out-of-range run value: %d leading zeroes.\n",
457+ leading_zeroes);
458+ return AVERROR_INVALIDDATA;
459+ }
446460 // Extract the low bits.
447461 low_bit_count = leading_zeroes + k_run;
448462 low_bit_shift = 16 - (1 + 2 * leading_zeroes + k_run);

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