Repository navigation
decoder: Do not keep an output stride narrower than the picture - #41
Conversation
u4_frm_buf_stride is set to the picture width after the header only when it is 0. It can still be smaller than the width there: - after a decode call returns IVD_RES_CHANGED (not a fatal error) and the application keeps feeding data without a reset, the stride of the previous, narrower sequence is kept for the new one; - a display width set with IVD_CMD_CTL_SETPARAMS before the first header is accepted without checking it against the picture width. The 420SP (UV and VU) and 422ILE format conversions advance the destination pointer at the end of each row by the unsigned difference "stride - width", so with a stride below the width they write outside the output buffer. With 420P output the rows overlap instead. Use the picture width when the stride is below it.
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.
|
After IVD_RES_CHANGED, application needs to flush all the buffers and then call reset and then start feeding the data. If this is not done, the decoder output is not guaranteed to be as expected. Given this, can we skip this? |
|
Thank you for merging the other four PRs. For this one, the effect is not just unexpected output: the format conversion writes outside the output buffer the application passed in. On The change only keeps the stride from going below the width. It does not change the requirement that the application flushes and resets after I'll leave it to you whether to take it. |
|
Thank you for the explaination. |
u4_frm_buf_strideis set to the picture width after the header only when it is 0. It can be smaller than the width at that point:IVD_RES_CHANGED(without the fatal bit) and the application keeps feeding data without a reset: the stride of the previous, narrower sequence is kept for the new one;IVD_CMD_CTL_SETPARAMSbefore the first header is accepted without being checked against the picture width.The 420SP (UV and VU) and 422ILE format conversions advance the destination pointer at the end of each row by the unsigned difference
stride - width, so with a stride below the width they write outside the output buffer (AddressSanitizer: SEGV on a write inimpeg2_fmt_conv_yuv420p_to_yuv420sp_uv,_yuv420sp_vuand_yuv422ile). With 420P output the rows overlap instead. The example and the fuzzer reset onIVD_RES_CHANGED, so they do not take the first path.This change uses the picture width when the stride is below it.
Tested on
main(275c536) with clang 21 and AddressSanitizer: both cases now decode to the end with the stride equal to the picture width, for all four output formats (before: SEGV in the three conversions above). The program and the streams are in this gist: https://gist.github.com/GeekQAQ/4c0803d0b94d7c65958cbcba726febc6 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).