fix out-of-bounds X underflow in SBR low-power QMF assembly - #225
Merged
fabiangreffrath merged 1 commit intoJun 25, 2026
Merged
Conversation
In SBR_LOW_POWER builds, sbr_process_channel() ends each time slot with an overlap add at X[l][kx_band - 1 + bsco_band]. For leading time slots (l < t_E[ch][0]) kx_band/bsco_band are taken from the previous frame (kx_prev/bsco_prev), which are still 0 on the first decoded frame. A first frame with a VARFIX/VARVAR grid and bs_abs_bord >= 1 makes t_E[ch][0] > 0, so l = 0 uses kx_prev == 0 and the index becomes -1, reading and writing X[0][-1] one element before the stack array. Skip the overlap add when kx_band + bsco_band == 0; there is no band below 0 to add. Normal frames have kx_band >= 5 and are unaffected.
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.
In
SBR_LOW_POWERbuilds,sbr_process_channel()(libfaad/sbr_dec.c) finishes each output time slot of the QMF matrixXwith an overlap add:For the leading time slots (
l < sbr->t_E[ch][0]) the band parameters are taken from the previous frame:kx_band = sbr->kx_prevandbsco_band = sbr->bsco_prev.On the very first decoded SBR frame both are still
0:sbr_infois zero-initialised, andsbr_save_prev_data()— the only writer ofkx_prev/bsco_prev— runs after the frame is processed.A first frame whose grid is
VARFIXorVARVARwithbs_abs_bord >= 1setsabs_bord_lead > 0, sot_E[ch][0] = rate * abs_bord_lead > 0. Thel = 0slot then takes thekx_prevpath, andkx_band - 1 + bsco_bandevaluates to-1, so the statement reads and writesX[0][-1]— onereal_tbefore the stack arrayX[MAX_NTSRHFG][64]. AddressSanitizer reports a stack-buffer-underflow at sbr_dec.c:447.The current-frame
kxis always>= 5(theqmf_start_channel()start tables andderived_frequency_table()), so the only waykx_band + bsco_bandcan be0is the first-framekx_prev == 0/bsco_prev == 0case. This is a different site from thehf_assembly()upper-bound (m + kx + 1 == 64) overflow.Fix: guard the overlap add with
if (kx_band + bsco_band > 0), skipping it when there is no band below0to add. Normal frames (kx_band >= 5) are unaffected and the high-quality (non-low-power) path does not contain this statement.Verified with a minimal crafted SBR payload driven through
sbr_extension_data()+sbrDecodeSingleFrame()in anSBR_LOW_POWER+ ASan build: stack-buffer-underflow at sbr_dec.c:447 before the change, clean afterwards (ret == 0, decode continues). The default andSBR_LOW_POWERconfigurations both build clean with-Wall.