Repository navigation
decoder: Zero the bytes after the input in the bitstream buffer - #38
Merged
Merged
Conversation
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().
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
harishdm
approved these changes
Nov 20, 2026
Member
|
Thank you for this PR. |
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.
Each decode call copies its input into
pu1_input_buffer, which hasMIN_BUFFER_BYTES_AT_EOSspare bytes afterMAX_BITSTREAM_BUFFER_SIZE. The bitstream reader prefetches 32-bit words, so when a slice is cut off at the end of the input, the decoder reads the bytes after the input. Those bytes are never cleared; they hold whatever an earlier, longer input left in the buffer, also acrossIVD_CMD_CTL_RESET.So the result of decoding a truncated input depends on what was decoded before. For example, after a reset, the first 160 bytes of a stream (sequence header, GOP header and a cut-off first slice) are consumed in one call or in two, and the picture differs, depending on which stream was decoded before the reset; a new decoder gives one result.
The reads stay inside the allocation with or without this change. The change only clears the spare bytes after copying the input in
impeg2d_dec_hdr()andimpeg2d_dec_frm(), so the bytes the reader sees past the input are always zero.Tested on
main(275c536) with clang 21 and AddressSanitizer: with the change, the truncated input gives the same bytes consumed and the same picture as on a new decoder after each of the four earlier streams (before: after three of them the first call consumed 160 bytes instead of 153, and all four gave a different picture). The program and the streams are in this gist: https://gist.github.com/GeekQAQ/d0a31657d236ac2979a3840821b0abe0 The default CMake build (Release, gcc and clang) has no new warnings, andmpeg2decgives byte-identical output before and after the change on 16 short test streams with 1 core, and with 4 cores except for a stream that starts with a B picture, whose 4-core output already varies from run to run onmain(a separate issue, sent as its own PR).