fix signed overflow in estimate_current_envelope energy sum - #227
Merged
fabiangreffrath merged 1 commit intoJul 12, 2026
Merged
Conversation
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.
Collaborator
|
Thank you! |
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.
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.if (nrg < -limit || nrg > limit) return 1guard 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
nrgto 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.