Skip to content

Allow DC coefficient differences beyond 16 bits and validate the reconstructed value - #268

Merged
cpncf merged 1 commit into
mainfrom
fix_dc_diff_range
Aug 13, 2026
Merged

Allow DC coefficient differences beyond 16 bits and validate the reconstructed value#268
cpncf merged 1 commit into
mainfrom
fix_dc_diff_range

Conversation

@kpchoi

@kpchoi kpchoi commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Fixes #254.

DC coefficients are in [-32768, 32767], so the difference between two neighboring blocks can legally reach 65535. RFC 9924 places the range constraint on the reconstructed coefficient, not on the difference, and the encoder writes such differences without any bound. The decoder rejected them, so it failed to decode conforming streams produced by its own encoder — 12-bit at QP 0-4, and any bit depth with a custom quantization matrix.

oapvd_vlc_dc_coef(): raise the abs_dc_diff limit from 32767 to 65535, and apply the sign with oapv_set_sign() instead of the misleadingly named oapv_set_sign16() (both operate on int, so this is a rename, not a behavior change).

dec_block(): compute the predicted DC in int and validate it against MIN_TX_VAL/MAX_TX_VAL before storing to the s16 coefficient buffer. This is where the range constraint belongs, and it also closes a pre-existing overflow: the old code summed two int values into an s16 with no check, so a value up to 65534 could wrap silently.

…nstructed value

Signed-off-by: KP Choi <kp5.choi@samsung.com>

@cpncf cpncf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@cpncf
cpncf merged commit fb54598 into main Aug 13, 2026
9 checks passed
@cpncf
cpncf deleted the fix_dc_diff_range branch August 13, 2026 12:06
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.

Decoder rejects valid streams when the DC coefficient difference exceeds 32767 (12-bit, low QP)

2 participants