fix(libSceAudioOut): reject oversized AudioOut2 grains at context creation #14997
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14997"
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 MarcZX10 on 2026-11-02T08:57:52Z.
What
sceAudioOut2ContextCreate(core/libs/prx/libSceAudioOut/src/AudioOut2Context.cpp) accepted anynum_grainsfrom the guest. The mix buffer isgrain * 2floats, so a huge value made theassignthrowstd::bad_alloc. The exception escaped theextern "C"entry point and the context allocated just before it leaked.The fix returns
SCE_AUDIO_OUT2_ERROR_INVALID_ARGUMENTfornum_grains > MAX_GRAINbefore any allocation, and holds the new context in astd::unique_ptruntil creation succeeds.Bound:
MAX_GRAIN = AUDIO_OUT2_SAMPLE_RATE * MAX_QUEUED_MS / 1000= 12000 frames (250 ms at 48 kHz).MAX_QUEUED_MSis the existing cap on pending queue time; the push path drops grains beyond it, so a grain longer than the cap is outside what the queue is built to carry. Existing callers use 256 (the default) and 1024 (AudioOut2Timing), both below the bound. The bound is chosen from the file's own constants, not from a console measurement.Commits (each one compiles on its own):
fix: add theMAX_GRAINconstant (unused until commit 2; the build does not use-Werror).fix: rejectnum_grains > MAX_GRAINbefore allocation.fix: hold the context in astd::unique_ptruntil success.test:OversizedGrainIsRefusedchecksnum_grains = 0xFFFFFFFFreturnsSCE_AUDIO_OUT2_ERROR_INVALID_ARGUMENTand leaves the handle unwritten.test: same check fornum_grains = 12001.test:num_grains = 12000(the bound) creates and destroys a context.Tested
run_tests.sh, targetaudio_out2_context_handles_tests, ctestaudio_out2_context_handleson head8f251ae886: BUILD-EXIT 0, "1/1 Test #2068: audio_out2_context_handles ....... Passed 0.10 sec", "100% tests passed, 0 tests failed out of 1" (VERIFY-FAILED line is the known host limitation in unrelated files).paramspointer (PROT_NONE page) and an unwritablectxslot (read-only page): both returnSCE_AUDIO_OUT2_ERROR_INVALID_ARGUMENT, and a later create still works. These cases were run only against the fixed code; they were not run against the unfixed code.std::bad_alloc(exit 134). With the fix it passes.audio_out2_timing,audio_out2_device_state, port tests) and Windows/macOS.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-02T10:22:58Z.
Review: COMMENTED
The new bound check dereferences
params->num_grainsdirectly before any guest-memory validation, and the success path still writes*ctxdirectly. A non-null invalidparamspointer can still crash before the oversized-grain guard, while an invalid outputctxcan leak the context inserted intog_contextsaftercontext.release(). Could this copy in the parameter struct first and safely copy out the handle before transferring ownership, with bad-pointer coverage?Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-02T11:30:11Z.
Review: DISMISSED
The remaining guest-pointer handling issue is still present at head ffd7c567660a718d7afd6d28711d7218147bde10.
paramsis dereferenced directly before the new size guard, and*ctxis written directly after inserting and releasing the context. An unreadable non-nullparamscan still crash the host. An unreadable non-nullctxcan fault after ownership has been released while the raw pointer remains registered ing_contexts. Please copy in the parameter structure and safely copy out the handle before committing ownership, with bad-pointer coverage.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-06T22:28:03Z.
Review: CHANGES_REQUESTED
The guest-pointer points from mashingaan are met at this head (
GuestCopyIn/GuestCopyOut, device closed in the deleter, bad-pointer test), and the tests fail without the fix. One point from oneandonlydean is still open:core/libs/prx/libSceAudioOut/src/AudioOut2Context.cpp:343(MAX_GRAIN, line 39): the 12000-frame cap is derived from the host's push-path backpressure (MAX_QUEUED_MS), not from the console's contract. It rejects sizes that worked before (12001, 16384), andAudioOut2ContextHandles.cpp:119-122pins 12000/12001 as if it were a console fact. Either cite the console's accepted-grain limit and error code, or drop the derived limit and handle allocation failure instead (catchstd::bad_allocaround themix.assignand return an error with the context cleaned up by theunique_ptr; the test then needs a size that fails to allocate rather than a boundary). If you keep a cap as an implementation limit, add a line todocs/dev/debt/libSceAudioOut.mdsaying it comes from the host queue limit and that the console's maximum and its error code are unverified, and make the test comment-free about it being a console boundary.