Repository navigation
decoder: keep NAL units in place when the NAL unit list grows - #4058
Open
anabobillo3 wants to merge 1 commit into
Open
anabobillo3 wants to merge 1 commit into
anabobillo3 wants to merge 1 commit into
Conversation
When an access unit has more NAL units than the list holds, ExpandNalUnitList() allocated a new list, copied every SNalUnit into it and freed the old one. The decoder keeps pointers into those units (pCtx->pSliceHeader, pCtx->pNalCur, the current dq layer's pRefPicMarking, pRefPicListReordering, pPredWeightTable and pRefPicBaseMarking), and they were left pointing into the freed list: the picture reordering reads pCtx->pSliceHeader (cisco#3684), and ParseDecRefPicMarking() writes through it on MMCO 5. Grow only the array of NAL unit pointers instead. The new block holds the bigger array and the new units; existing units keep their address and their order, and each block is linked from the access unit and freed in MemFreeNalList(). Fixes cisco#3684
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.
Fixes #3684.
When an access unit has more NAL units than the decoder's NAL unit list holds,
MemGetNextNal()grows the list throughExpandNalUnitList(). That function allocated a whole new list, copied everySNalUnitinto it and freed the old one, so each NAL unit moved to a new address. The decoder keeps plain pointers into those units while it decodes:pCtx->pSliceHeader(set inWelsDqLayerDecodeStart()): the picture reordering inwelsDecoderExt.cppreads it (BufferingReadyPicture(),ReleaseBufferedReadyPictureReorder()), which is the read reported in Heap use after free on ISVCDecoder::DecodeFrameNoDelay #3684, andParseDecRefPicMarking()writespCtx->pSliceHeader->iPicOrderCntLsbthrough it on MMCO 5;pCtx->pNalCur, and the current dq layer'spRefPicMarking,pRefPicListReordering,pPredWeightTableandpRefPicBaseMarking.After a list growth all of them pointed into freed memory.
Change
NAL units no longer move once allocated.
ExpandNalUnitList()allocates a block that holds only the new units and the bigger array of NAL unit pointers. It copies the existing pointers into that array unchanged, keeping their order, and links the block from the access unit (SAccessUnit::pExpandedBlock).MemFreeNalList()frees every linked block along with the list. TheSAccessUnititself doesn't move either. This covers every pointer into a NAL unit, current and future, so nothing needs retargeting after a growth.Test
DecoderNalUnitListTest.ExpandNalUnitListKeepsNalUnitsInPlace(intest/decoder/DecUT_ParseSyntax.cpp) takes every NAL unit of a new list, then grows the list twice throughMemGetNextNal(). It checks that the units handed out before are still the same list entries, with their contents intact, and that a write through a slice header pointer taken before the growth lands in the list.Results (ASan build,
USE_ASM=No,BUILDTYPE=Debug):codec_unittest, run test by test before and after the change, gives the same results (523 tests, all passing after).ParseDecRefPicMarking()throughpCtx->pSliceHeader, withDecodeFrame2()and error concealment on, and also in parse-only mode. With this change it decodes cleanly in both modes. The input attached to Heap use after free on ISVCDecoder::DecodeFrameNoDelay #3684 no longer triggers the error on current master with the driver from the issue (the stream now takes another path), but the list growth and the danglingpCtx->pSliceHeaderit reported are the same.