Repository navigation
decoder: Clear recent reference fields on reset - #36
Merged
Merged
Conversation
harishdm
requested changes
Oct 23, 2026
impeg2d_api_reset() clears aps_ref_pics[] but keeps as_recent_fld[][], which still points into the picture buffers of the previous stream. When the next stream starts with a P picture or an open-GOP B picture, impeg2d_pre_pic_dec_proc() takes the missing reference from as_recent_fld instead of the current picture buffer, so the decoded output mixes in pixels from the previous stream. With shared display buffers that the application replaced after the reset, the reference points into freed memory. Clear as_recent_fld in the reset so that the decoder behaves as a newly created instance.
GeekQAQ
force-pushed
the
reset-clear-recent-fld
branch
from
October 23, 2026 15:07
8e69797 to
4493e90
Compare
harishdm
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As suggested in the reply to our private report, here is the reset fix as a regular PR.
impeg2d_api_reset()clearsaps_ref_pics[]but notas_recent_fld[][]. AfterIVD_CMD_CTL_RESET, if the next stream starts with a P picture or an open-GOP B picture,impeg2d_pre_pic_dec_proc()fills the missing reference fromas_recent_fld, which still points into the previous stream's picture buffers, where a new decoder would use the current picture buffer:u4_share_disp_buf = 0, the decoded output of the new stream mixes in pixels from the previous stream;IVD_CMD_SET_DISPLAY_FRAME) after the reset, motion compensation reads freed memory.This change clears
as_recent_fldin the reset.Testing on
main(e2dbb98), clang 21: a program that decodes a stream, resets, and decodes a stream starting with an open-GOP B picture now gives the same output as a new decoder (it differed before); in the shared-buffer case above, AddressSanitizer reported a heap-use-after-free read before the change and reports nothing after it. The default CMake build has no new warnings.Left unchanged (happy to follow up if you want any of these):
u4_num_frames_decodedis not reset, so after a reset a stream starting with a B picture outputs its first frame one call earlier than on a new decoder. Resetting it would also reset theNUM_FRAMES_LIMITcount.examples/decoder/main.crelies on this).