From 070a6d259518b8d98d4155c6627de84946fb0883 Mon Sep 17 00:00:00 2001 From: Pu Cheng Date: Fri, 20 Nov 2026 07:52:54 +0800 Subject: [PATCH] decoder: Zero the bytes after the input in the bitstream buffer The input of each decode call is copied into pu1_input_buffer, which has MIN_BUFFER_BYTES_AT_EOS spare bytes after MAX_BITSTREAM_BUFFER_SIZE. The bitstream reader prefetches 32-bit words, so when a slice is cut off at the end of the input it reads the bytes after the input. Those bytes were whatever an earlier, longer input left in the buffer, and were not cleared by IVD_CMD_CTL_RESET either: the bytes consumed and the decoded picture for a truncated input depended on what had been decoded before, e.g. on the stream decoded before a reset. Clear the spare bytes after copying the input in impeg2d_dec_hdr() and impeg2d_dec_frm(). --- decoder/impeg2d_decoder.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/decoder/impeg2d_decoder.c b/decoder/impeg2d_decoder.c index fe0b870..9465481 100644 --- a/decoder/impeg2d_decoder.c +++ b/decoder/impeg2d_decoder.c @@ -107,6 +107,7 @@ void impeg2d_dec_hdr(void *pv_dec,impeg2d_video_decode_ip_t *ps_ip, } memcpy(ps_dec->pu1_input_buffer, ps_ip->s_ivd_video_decode_ip_t.pv_stream_buffer, u4_size); + memset(ps_dec->pu1_input_buffer + u4_size, 0, MIN_BUFFER_BYTES_AT_EOS); impeg2d_bit_stream_init(&(ps_dec->s_bit_stream), ps_dec->pu1_input_buffer, u4_size); @@ -207,6 +208,7 @@ void impeg2d_dec_frm(void *pv_dec,impeg2d_video_decode_ip_t *ps_ip, } memcpy(ps_dec->pu1_input_buffer, ps_ip->s_ivd_video_decode_ip_t.pv_stream_buffer, u4_size); + memset(ps_dec->pu1_input_buffer + u4_size, 0, MIN_BUFFER_BYTES_AT_EOS); ps_dec->pu1_inp_bits_buf = ps_dec->pu1_input_buffer;