LibAtrac9: a malformed block writes past Block::Gradient[31] (gradient end unit 32..47) #2345
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T16:04:17Z.
What
The vendored
3rdparty/LibAtrac9(shadps4-emu/ext-LibAtrac9, pinned at946e05a= upstream master) writes out of bounds for a block whose gradient end unit is 32..47.Block::Gradientisint Gradient[31](C/src/structures.h:114), butReadGradientParamsvalidates the gradient units against 48, not 31:C/src/unpack.c:175—block->GradientEndUnit = ReadInt(br, 6) + 1;→ 1..64C/src/unpack.c:189—if (block->GradientEndUnit < 0 || block->GradientEndUnit >= 48)→ accepts up to 47C/src/bit_allocation.c:13—for (int i = 0; i < block->GradientEndUnit; i++) block->Gradient[i] = block->GradientStartValue;→ forGradientEndUnitin [32,47] this writesGradient[31..46], past the array and ontoGradientModeand the fields after it.The 48 bound matches
GradientCurves[48][48]; it does not match the 31-elementGradientarray.Reachable from title data
libSceAjm.native/src/Ajm.cpp:646hands the guest buffer straight to the decoder (DecodeAt9Frame(instance, input.data() + consumed, …)→UnpackFrame→ReadGradientParams→CreateGradient). A streamed/corrupt AT9 block withGradientMode == 0and a 6-bit end unit ≥ 31 reaches the overrun; nothing on the AnyPS5 side validates those units first.Evidence
Gradient[31]vs the< 48guard vs thei < GradientEndUnitloop).-fsanitize=bounds,addresscatching theGradientoverrun for its0x07-filled block, and that the overrun is inBlockin this library. #2163 only changes the test input so it no longer reaches the overrun; the overrun itself is untouched.d70b8998): at Debug/-O0guest_ajm_testsaborts (exit 134) atGuestAjm.cpp:597; with #2163 (block byte0xA5) it exits 0. Release passes on both arms, so this is-O0-only for the test, but the out-of-bounds write exists at every optimisation level.Why filed here, not upstream
Upstream has issues disabled (
hasIssuesEnabled: false), and the pinned commit is already upstreammaster, so there is no newer commit to bump to. A fix has to be a fork/pin or a patch carried against the submodule.Suggested fix
Bound the gradient units to the array in
ReadGradientParams(rejectGradientEndUnit > 31), or sizeGradientto matchGradientCurves(48).GradientStartUnit <= GradientEndUnitis already checked, so bounding the end unit is sufficient.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by ArchitDewan on 2026-10-09T17:44:30Z.
I’d like to take on #2345 and submit a PR to fix the LibAtrac9 gradient bounds issue, with a regression test, if no one else is working on it.