diff options
author | Hamsalekha S <hamsalekha.s@ittiam.com> | 2017-07-04 17:06:50 +0530 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-11-28 03:26:46 +0000 |
commit | e86d3cfd2bc28dac421092106751e5638d54a848 (patch) | |
tree | 11065a2f169e112b55e7a777b9621f3016033eb6 | |
parent | 42cf02965b11c397dd37a0063e683cef005bc0ae (diff) | |
download | android_external_libavc-e86d3cfd2bc28dac421092106751e5638d54a848.tar.gz android_external_libavc-e86d3cfd2bc28dac421092106751e5638d54a848.tar.bz2 android_external_libavc-e86d3cfd2bc28dac421092106751e5638d54a848.zip |
Decoder: Increased allocation and added checks in sei parsing.
This prevents heap overflow while parsing sei_message.
Bug: 63122634
Test: ran PoC on unpatched/patched
Change-Id: I61c1ff4ac053a060be8c24da4671db985cac628c
(cherry picked from commit f2b70d353768af8d4ead7f32497be05f197925ef)
-rw-r--r-- | decoder/ih264d_api.c | 3 | ||||
-rw-r--r-- | decoder/ih264d_defs.h | 3 | ||||
-rw-r--r-- | decoder/ih264d_sei.c | 7 |
3 files changed, 9 insertions, 4 deletions
diff --git a/decoder/ih264d_api.c b/decoder/ih264d_api.c index 0341389..bb5caf4 100644 --- a/decoder/ih264d_api.c +++ b/decoder/ih264d_api.c @@ -2052,7 +2052,8 @@ WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op) void *pv_buf; void *pv_mem_ctxt = ps_dec->pv_mem_ctxt; size = MAX(256000, ps_dec->u2_pic_wd * ps_dec->u2_pic_ht * 3 / 2); - pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); + pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, + size + EXTRA_BS_OFFSET); RETURN_IF((NULL == pv_buf), IV_FAIL); ps_dec->pu1_bits_buf_dynamic = pv_buf; ps_dec->u4_dynamic_bits_buf_size = size; diff --git a/decoder/ih264d_defs.h b/decoder/ih264d_defs.h index 4622775..260e358 100644 --- a/decoder/ih264d_defs.h +++ b/decoder/ih264d_defs.h @@ -108,6 +108,9 @@ /* For 420SP */ #define YUV420SP_FACTOR 2 +/*To prevent buffer overflow access; in case the size of nal unit is + * greater than the allocated buffer size*/ +#define EXTRA_BS_OFFSET 16*16*2 /** *************************************************************************** diff --git a/decoder/ih264d_sei.c b/decoder/ih264d_sei.c index 800f2c9..098a1f3 100644 --- a/decoder/ih264d_sei.c +++ b/decoder/ih264d_sei.c @@ -336,7 +336,7 @@ WORD32 ih264d_parse_sei_message(dec_struct_t *ps_dec, ui4_payload_type = 0; u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8); - while(0xff == u4_bits) + while(0xff == u4_bits && !EXCEED_OFFSET(ps_bitstrm)) { u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8); ui4_payload_type += 255; @@ -345,7 +345,7 @@ WORD32 ih264d_parse_sei_message(dec_struct_t *ps_dec, ui4_payload_size = 0; u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8); - while(0xff == u4_bits) + while(0xff == u4_bits && !EXCEED_OFFSET(ps_bitstrm)) { u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8); ui4_payload_size += 255; @@ -370,7 +370,8 @@ WORD32 ih264d_parse_sei_message(dec_struct_t *ps_dec, { H264_DEC_DEBUG_PRINT("\nError in parsing SEI message"); } - while(0 == ih264d_check_byte_aligned(ps_bitstrm)) + while(0 == ih264d_check_byte_aligned(ps_bitstrm) + && !EXCEED_OFFSET(ps_bitstrm)) { u4_bits = ih264d_get_bit_h264(ps_bitstrm); if(u4_bits) |