Skip to content

decoder: Do not report stale reinit dimensions for too small sequences - #40

Merged
harishdm merged 1 commit into
ittiam-systems:mainfrom
GeekQAQ:small-dims-reinit
Nov 20, 2026
Merged

harishdm merged 1 commit into
ittiam-systems:mainfrom
GeekQAQ:small-dims-reinit

Conversation

@GeekQAQ

@GeekQAQ GeekQAQ commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

When a sequence is larger than the create-time maximum, impeg2d_dec_seq_hdr() returns IMPEG2D_UNSUPPORTED_DIMENSIONS and stores its size in u2_reinit_max_width/height, which the decode call reports as u4_pic_wd/ht so that the application can create a decoder of that size. The two branches that reject a width or height below MIN_WIDTH/MIN_HEIGHT return the same error without writing these fields.

So a decoder that has seen an oversized sequence reports that sequence's size for a later, too small one: with a 176x144 decoder, after a 352x288 sequence, a sequence 8 pixels wide is rejected with u4_pic_wd/ht 352x288; a new decoder reports 0x0. IVD_CMD_CTL_RESET does not clear the fields, so the same happens after a reset (the fuzzer resets on IMPEG2D_UNSUPPORTED_DIMENSIONS and reallocates its frame from the reported size).

This change clears the reinit dimensions in the two too-small branches, which is what a new decoder reports.

Tested on main (275c536) with clang 21 and AddressSanitizer: after the oversized sequence, with or without a reset, the too small sequence now reports 0x0 like a new decoder (352x288 before). The program and the streams are in this gist: https://gist.github.com/GeekQAQ/f3806a8a1a18633cc510ceae8b85d201 The default CMake build (Release, gcc and clang) has no new warnings, and mpeg2dec gives 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 on main (a separate issue, sent as its own PR).

When a sequence is larger than the create-time maximum,
impeg2d_dec_seq_hdr() returns IMPEG2D_UNSUPPORTED_DIMENSIONS and stores
its size in u2_reinit_max_width/height, which the decode call reports as
u4_pic_wd/ht so that the application can create a decoder of that size.
The branches that reject a width or height below MIN_WIDTH/MIN_HEIGHT
return the same error without writing these fields, so a decoder that
had earlier seen an oversized sequence reported that sequence's size for
the too small one (before or after IVD_CMD_CTL_RESET, which does not
clear the fields either). A new decoder reports 0x0.

Clear the reinit dimensions in the two too-small branches.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
harishdm merged commit d6eb340 into ittiam-systems:main Nov 20, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants