Skip to content

Commit 7bb0255

Browse files
vigneshvgandi34
authored andcommitted
DO NOT MERGE | libvpx: cherry-pick aa1c813 from upstream
Description from upstream: vp9: Fix potential SEGV in decoder_peek_si_internal decoder_peek_si_internal could potentially read more bytes than what actually exists in the input buffer. We check for the buffer size to be at least 8, but we try to read up to 10 bytes in the worst case. A well crafted file could thus cause a segfault. Likely change that introduced this bug was: https://chromium-review.googlesource.com/#/c/70439 (git hash: 7c43fb6) Bug: 30013856 Change-Id: If556414cb5b82472d5673e045bc185cc57bb9af3 (cherry picked from commit bd57d587c2eb743c61b049add18f9fd72bf78c33) (cherry picked from commit b03db1e)
1 parent 9837fbc commit 7bb0255

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

libvpx/vp9/vp9_dx_iface.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
174174
vpx_decrypt_cb decrypt_cb,
175175
void *decrypt_state) {
176176
int intra_only_flag = 0;
177-
uint8_t clear_buffer[9];
177+
uint8_t clear_buffer[10];
178178

179179
if (data + data_sz <= data)
180180
return VPX_CODEC_INVALID_PARAM;
@@ -188,6 +188,11 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
188188
data = clear_buffer;
189189
}
190190

191+
// A maximum of 6 bits are needed to read the frame marker, profile and
192+
// show_existing_frame.
193+
if (data_sz < 1)
194+
return VPX_CODEC_UNSUP_BITSTREAM;
195+
191196
{
192197
int show_frame;
193198
int error_resilient;
@@ -201,15 +206,19 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
201206
if (profile >= MAX_PROFILES)
202207
return VPX_CODEC_UNSUP_BITSTREAM;
203208

204-
if ((profile >= 2 && data_sz <= 1) || data_sz < 1)
205-
return VPX_CODEC_UNSUP_BITSTREAM;
206-
207209
if (vpx_rb_read_bit(&rb)) { // show an existing frame
210+
// If profile is > 2 and show_existing_frame is true, then at least 1 more
211+
// byte (6+3=9 bits) is needed.
212+
if (profile > 2 && data_sz < 2)
213+
return VPX_CODEC_UNSUP_BITSTREAM;
208214
vpx_rb_read_literal(&rb, 3); // Frame buffer to show.
209215
return VPX_CODEC_OK;
210216
}
211217

212-
if (data_sz <= 8)
218+
// For the rest of the function, a maximum of 9 more bytes are needed
219+
// (computed by taking the maximum possible bits needed in each case). Note
220+
// that this has to be updated if we read any more bits in this function.
221+
if (data_sz < 10)
213222
return VPX_CODEC_UNSUP_BITSTREAM;
214223

215224
si->is_kf = !vpx_rb_read_bit(&rb);

0 commit comments

Comments
 (0)