Repository navigation
Conversation
Dextroid17
left a comment
There was a problem hiding this comment.
The fix holds on Linux, and the added test is what proves it. Head f7cd1d4f6 (two commits: 961f2afb5 staging, f7cd1d4f6 retry); GitHub's base is e7c70a2df, whose fork point from this branch is 9bc362351 — Apr.cpp is byte-identical in both, so use one of those two for the file, not git diff e7c70a2df..HEAD (77 commits of churn). I built guest_ampr_tests and guest_ampr_threads_tests in a worktree and ran two arms: head Apr.cpp + head test file, then base Apr.cpp + head test file.
head 100% tests passed out of 2 (guest_ampr_markers, guest_ampr_threads)
direct run of guest_ampr_tests: exit 0
baseline guest_ampr_markers (Subprocess aborted) → GuestAmpr.cpp:642: requirement failed
direct run: exit 134
Worth noting which line fails: the message assertion at GuestAmpr.cpp:641 passes on the base too — the base already throws returned 5 of 16 bytes. Line 642 is the destination check, so that is the load-bearing part of the new test, and it is the bug: e7c70a2df has stream.read(reinterpret_cast<char*>(command.destination), …) at line 165 with GuestArena::HostWrite destination(…) and its Open() check two lines above, so a short read wrote into guest memory and then threw. Guard-before-copy is the right shape.
Three things I noticed, in decreasing weight:
- A reading of the new order, not a run: the destination guard now sits below a host allocation sized by a guest value. In the head,
std::vector<char> staging(static_cast<std::size_t>(command.size))is line 161 andGuestArena::HostWrite destination(…)/Open()are 179-180 — and on LinuxGuestArenaBeginHostWrite_nid_postfixcallsGuestWriteWatch…and returns true unconditionally, so that guard rejects nothing here either before or after the move; on Windows it checks shared-view writability, not a size bound.command.sizeis astd::uint64_tout of the record, and the decoder bounds the record (APR: truncated command payloadline 266,APR: malformed command572), not this field. Through the guest-facing encoder it is capped at0x100000000(ValidReadLength,libSceAmpr/Export.cpp:60;GuestAmpr.cpp:769pins that0x100000001is rejected), so the worst reachable allocation is a 4 GiB zero-filled vector; a hand-built record can put2^64-1there and getstd::length_errorinstead of the intended message. If the guard is meant to run first, moving it above line 161 costs nothing — it does not depend on the read. - The second commit is not in the body.
f7cd1d4f6adds the three-attempt retry loop, a different topic from staging (the checklist asks for one topic per PR), and the "What" paragraph describes only the staging change. Either a sentence there or a split, plus a word on what the retry targets: by inspection of the loop, a plain short read (eofbit/failbit) takes theelsebranch, clears the flags, re-seeksoffset + readand re-reads the same tail, so only thebadbitpath (close/reopen) can make progress — the head's own test observes exactly 5 of 16 bytes after all three attempts. - Coverage: the new test pins the short-read path, which is the fix. An invalid destination cannot be exercised at all on Linux (the guard is the no-op above), and
size == 0is rejected by the encoder, so theif (read != 0)before thememcpycan only be false for a hand-built record — withsize > 0either the copy runs or the short read has already thrown above it.
Checked and fine: dropping #include <cerrno> leaves no errno use anywhere in the file — only the GUEST_EINVAL constants.
Written with AI assistance.
Hermes Agent 🤖 at your service
|
Closing: main already throws on a short or failed APR read, so leaving the destination untouched before that throw changes nothing a title can see, while the staging vector adds a second copy to every APR read. The three-attempt loop ( Reopen with a title where the staged read changes what it sees, without the retry. |
Add per-sample pixel inputs, correct tessellation component addressing, publish small imported GPU images at flips, prepare static shader ABIs on the background pool, and size Windows write-watch queries. Integrate pipelined release and metadata-fill corrections, finish resident linear targets, recycle cached fragment descriptor sets, and return positional-read errors while retaining descriptor isolation and owned-layout lifetime handling. Validation: complete configured build and 52 targeted Linux checks pass, including full graphics/submission suites and upstream regression fixtures. Windows runtime execution and Sackboy rendering remain to be verified. Rejected APR staging/retry PR boykopovar#4413 and the unpublished blend-disabling GT7 workaround are excluded.
What
Tested
Windows — built and ran the APR test suite; no game-specific test was run for this isolated change.
cmake --build build --target guest_ampr_tests— passedctest --test-dir build -R '^guest_ampr_markers$' --output-on-failure— passedpython tools/check_conventions.py --base upstream/main— passedChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)