CVE-2026-58876 AI-generated analysis
platform/external/aac, libSBRdec (Fraunhofer AAC decoder, parametric stereo decoder creation/reset)
CreatePsDec in libSBRdec no longer frees a caller-owned parametric stereo decoder instance on its error path (only locally allocated instances), and the caller sbrDecoder_ResetElement now explicitly calls DeletePsDec on failure so the handle is freed and cleared instead of left dangling.
Root cause
CreatePsDec (libSBRdec/src/psdec.cpp) has two entry paths: when *h_PS_DEC is NULL it allocates a new instance via GetRam_ps_dec(), otherwise it reuses the existing instance ("Reset an open instance", h_ps_d = *h_PS_DEC). If any later step fails (for example an aacSamplesPerFrame value that the new test calls invalid, 512), control jumps to bail, which unconditionally called DeletePsDec(&h_ps_d). In the reset path this freed the instance that the caller still references through *h_PS_DEC (self->hParametricStereoDec in sbrDecoder_ResetElement), and only the local copy h_ps_d was cleared. The caller's handle therefore pointed to freed memory, and any later use or deletion of self->hParametricStereoDec was a use-after-free or double free.
How the fix works
- libSBRdec/src/psdec.cpp:CreatePsDec: initializes h_ps_d to NULL and adds a local flag h_ps_d_allocated, set to 1 only after GetRam_ps_dec() succeeds in the allocation path. The bail label now calls DeletePsDec(&h_ps_d) only if h_ps_d_allocated && h_ps_d != NULL, so an instance passed in by the caller for reset is never freed inside CreatePsDec.
- libSBRdec/src/sbrdecoder.cpp:sbrDecoder_ResetElement: in the numSbrElements == 1 switch over coreCodec (AOT_AAC_LC, AOT_SBR, AOT_PS, AOT_ER_AAC_SCAL, AOT_DRM_AAC, AOT_DRM_SURROUND), when CreatePsDec(&self->hParametricStereoDec, samplesPerFrame) returns non-zero the caller now calls DeletePsDec(&self->hParametricStereoDec) before setting sbrError = SBRDEC_CREATE_ERROR and jumping to bail. Per the commit message DeletePsDec reclaims the memory and clears the handle, so self->hParametricStereoDec is NULL afterwards rather than dangling.
- Android.bp and libSBRdec/tests/libSBRdec_test.cpp: adds a host-capable cc_test libSBRdec_test (LibSbrDecTest.CreatePsDecResetUAF) that creates a PS decoder with 1024 samples, calls CreatePsDec again with 512 to force a reset-path failure, then deletes the handle and expects it to be NULL. This is test scaffolding, not part of the runtime fix.
Completeness
- The fix covers both halves of the problem: CreatePsDec no longer frees memory it does not own, and the one caller shown (sbrDecoder_ResetElement) frees and clears the handle on failure.
- The allocation path is unchanged in effect: a locally allocated instance that fails later is still freed inside CreatePsDec. Whether *h_PS_DEC is assigned before the failure points (and thus whether the caller's subsequent DeletePsDec sees NULL or a freed pointer) is not visible in the provided context.
- Only sbrDecoder_ResetElement is updated as a caller. Any other caller of CreatePsDec that relied on CreatePsDec cleaning up a reset instance on failure would now hold a still allocated instance; no other caller appears in the material.
- The error-path ownership contract is now: CreatePsDec cleans up only what it allocated; callers own cleanup of pre-existing instances.
Behavior changes
- On a failed reset of an existing PS decoder, self->hParametricStereoDec is freed by the caller and set to NULL; previously it was freed inside CreatePsDec and left non-NULL.
- Return values are unchanged: CreatePsDec still returns non-zero on failure and sbrDecoder_ResetElement still returns SBRDEC_CREATE_ERROR.
- New test module libSBRdec_test (host_supported, device-tests suite) is added to the build.
Per major
- Android 14: same fix: platform/external/aac 24eddc6f0bc4 in android-security-14.0.0_r31; source hunks in psdec.cpp and sbrdecoder.cpp plus new test and Android.bp cc_test (without a team attribute).
- Android 15: same fix: platform/external/aac b974bbb9ab3e in android-security-15.0.0_r19; identical source hunks; the Android.bp cc_test additionally carries team: trendy_team_android_media_audio_framework.
- Android 16: same fix: platform/external/aac 72df28d59e0f in android-security-16.0.0_r10; identical source hunks and the same Android.bp cc_test with team attribute (Android.bp base blob differs, 1c7192d).
- Android 17: same fix with relocated paths: platform/external/aac 6b8c6cbab2b7 in android-security-17.0.0_r3; identical source hunks, but files are under a cpp/ prefix (cpp/Android.bp, cpp/libSBRdec/src/psdec.cpp, cpp/libSBRdec/src/sbrdecoder.cpp, cpp/libSBRdec/tests/libSBRdec_test.cpp).
Unknowns
- Whether CreatePsDec assigns *h_PS_DEC before the failure points in the allocation path, and how DeletePsDec behaves when passed a NULL handle (the caller now calls it unconditionally on failure); the relevant lines are not in the provided context.
- The exact failure condition inside CreatePsDec that is reachable from real streams and the concrete call sequence that re-enters sbrDecoder_ResetElement with an existing PS decoder.
- Whether CreatePsDec has callers other than sbrDecoder_ResetElement; none are shown in the material.
- Whether the fix is also delivered through APEX/mainline module updates; the material does not show this.