History

apv_entropy: Improve robustness to bitstream errors

Mark Thompson committed 1 year ago

Commit ea457e51 parent 2aa20951 file · +16 −0Browse files

Unified · Split

libavcodec/apv_entropy.c+16−0
@@ -84,6 +84,14 @@ static unsigned int apv_read_vlc(GetBitContext *gbc, int k_param, · 83 unmodified lines
8484 next_bits = show_bits(gbc, 16);
8585 leading_zeroes = 15 - av_log2(next_bits);
8686
87+ if (leading_zeroes == 0) {
88+ // This can't happen mid-stream because the lookup would
89+ // have resolved a leading one into a shorter code, but it
90+ // can happen if we are hitting the end of the buffer.
91+ // Return an invalid code to propagate as an error.
92+ return APV_MAX_TRANS_COEFF + 1;
93+ }
94+
8795 skip_bits(gbc, leading_zeroes + 1);
8896
8997 return (2 << k_param) +
@@ -182,6 +190,14 @@ int ff_apv_entropy_decode_block(int16_t *coeff, · 92 unmodified lines
182190 else
183191 level = abs_ac_coeff_minus1 + 1;
184192
193+ if (level < APV_MIN_TRANS_COEFF ||
194+ level > APV_MAX_TRANS_COEFF) {
195+ av_log(state->log_ctx, AV_LOG_ERROR,
196+ "Out-of-range AC coefficient value: %d "
197+ "(from prev_level %d abs_ac_coeff_minus1 %d sign_ac_coeff %d)\n",
198+ level, prev_level, abs_ac_coeff_minus1, sign_ac_coeff);
199+ }
200+
185201 coeff[ff_zigzag_direct[scan_pos]] = level;
186202
187203 prev_level = abs_ac_coeff_minus1 + 1;

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