Skip to content

fix signed overflow in estimate_current_envelope energy sum - #227

Merged
fabiangreffrath merged 1 commit into
knik0:masterfrom
netliomax25-code:sbr-envelope-energy-int64
Jul 12, 2026
Merged

fix signed overflow in estimate_current_envelope energy sum#227
fabiangreffrath merged 1 commit into
knik0:masterfrom
netliomax25-code:sbr-envelope-energy-int64

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor
  1. estimate_current_envelope() sums the per-band QMF energy into nrg, a 32-bit real_t, over the envelope's time slots and (in the second loop) its QMF bins. On ordinary HE-AAC/HE-AACv2 content this running sum passes INT32_MAX and the signed addition overflows.
  2. The if (nrg < -limit || nrg > limit) return 1 guard right after is meant to reject over-range energies, but it reads the already-wrapped value, so it only rejects sums that happen to land negative; one that wraps back into range is accepted and a corrupt E_curr goes to the limiter.

Widened nrg to int64_t in the fixed-point build so the accumulation and the limit test are evaluated in range. Both loops share the variable, so both are covered. The float build is untouched and valid fixed-point decode output is byte-identical; a UBSan build reported signed-integer-overflow at this line on a normal HE-AAC stream and is clean after the change.

The per-band QMF energy is summed into a 32-bit real_t over the envelope time slots and QMF bins; on ordinary HE-AAC content the sum passes INT32_MAX and wraps before the following limit test can reject it. Accumulate in int64_t on the fixed-point build so the sum and the test stay in range.
@fabiangreffrath
fabiangreffrath merged commit fd16df1 into knik0:master Jul 12, 2026
6 checks passed
@fabiangreffrath

Copy link
Copy Markdown
Collaborator

Thank you!

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.

2 participants