fix(libc): check qsort_s arguments as titles' libc.prx does #12598
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12598"
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 JJenkx on 2026-10-28T22:20:48Z.
Current-main integration — 2026-11-05. Exact head
dcb4925e80a2450ba153730c71e132c4a643ffacretains previous public3529e1b3ba9f0d6e725a582de84c01506a8e97edand tested main6d173c1a19788ff69d43b3d0ca62833e312ef939as ancestors. The measured qsort_s function remains byte-identical to the previous public head. Main’s qsort_r and unrelated routines are retained. The accepted zero-size host no-op and the documented bundled-module extreme-boundary SIGFPE caveat remain; no new reference result is claimed.Linux x86-64, GCC16.2.1, Ninja Release: actual production modules and focused fixture owners rebuilt; 4/4 runtime tests pass, zero skips:
guest_qsort,guest_bounds_checking,guest_safe_errors,guest_crt. Matching pinned main passes all25 selected baseline groups. Production NID patching, conventions/whitespace, and MinGW syntax forFileAndHeap.cpppass.Public-header audit: failed on both pinned main and this head with the same five missing
WKSecurityOrigin*declarations (Create,CopyToString,CopyHost,CopyProtocol,GetPort), with no additional declaration errors. The failure is retained in the logs; no all-green header/full-suite claim is made. The concrete shared-main repair is #16010, exact head545e24b2ee2e549001421f7fc9f87ff801f3423c. Its independent qualification reports a green audit of 406 libraries/30,572 exports and two standalone units compiled by each of GCC and MinGW. A maintainer still needs to merge that repair and rerun the affected checks; this unmodified qualification tree is not relabelled header-green.The older-main Windows
DepthSurface::createSampleShadowallocation compile error is already corrected by merged #15855. This head contains that fix, and its DepthSurface.cpp/ImageMemory.hpp blobs match the fixing source. The fix’s hosted Windows build passed; that is attributed upstream evidence, not a Windows build/runtime result for this head. No duplicate AGC change was added. A final merge preview against newer main7ad9749ed0311cc91d69bc7c690d09c92b9d42d0is clean; qualification remains pinned to6d173c1a19788ff69d43b3d0ca62833e312ef939.Source/parent/provider/gitlink proofs, commands, raw logs, JUnit, hashes and known baseline failure. Historical platform, module-reference and performance reports below retain their original pins; no new Windows/macOS, SDK/physical-console, title/GPU or performance run.
Earlier pinned reports and the contribution template follow.
What
qsort_snow checks its arguments the way thelibc.prxthat titles ship does. Measured natively on PPSA07923 and PPSA05916, which agree:SIZE_MAX >> 3(2^61 and up) is a violation.mainthe limit wasSIZE_MAX >> 1, so a count from 2^61 to 2^63 was accepted and sorted past the array: the comparison run crashed there."qsort_s: bad argument", withEINVALand a null pointer. Onmaineach case had its own message, such as"qsort_s : n > RSIZE_MAX"or"qsort_s : a == NULL".The rest already matched the titles and is unchanged:
n == 0with a null base or comparator is accepted;bsearch_salready matched on every case below, so it doesn't change. The debt entry, which said the console's behaviour was unverified, now states the measured rule.Merge note for my #9688 (the
qsortandqsort_ssort order): the two PRs edit the sameqsort_sdebt entry, which conflicts textually. The resolution is #9688's entry with two changes:EINVALafter calling the constraint handler whennoresexceedsRSIZE_MAX, or whennis not 0 andaorcmpis null" becomes this PR's measured sentence;The code and the tests merge cleanly.
Tested
Current-main refresh — 2026-11-04. Head
3529e1b3ba9f0d6e725a582de84c01506a8e97edmerges main9ab6a281ea61c9e62a7eb07eb4cef8f19ede1c5cwhile retaining the prior public head as an ancestor. Main’s newer code, regression fixtures and debt entries are preserved alongside this topic.Linux x86-64, GCC16.2.1, Ninja Release: actual libc, libkernel and libSceAmpr CMake owners rebuilt coherently.
guest_qsort,guest_bounds_checking,guest_safe_errors,guest_crteach pass three consecutive runs (12 passes, zero skips). The same groups pass three times on pinned main. Public-header audit and conventions pass. Original licence-notice trailing whitespace is retained where present. The scoped recipe reuses frozen ZArchive/zstd providers; this is not a whole-project build. No new Windows, bundled-SDK, physical-console, title/GPU or FPS measurement is claimed; earlier reports retain their original pins.Exact source/parent proofs, per-branch patches/input manifests, build and CTest logs/JUnit, library/executable hashes and scoped CMake recipe, SHA-256
97a2377bc996be1690e8853e1ea090a98b5ed808bcc37a15a5cdada5c2e00845(download verified). AI-assisted: yes (Codex).Current-main integration — 2026-11-04. Head
1be723b023bdbb8caa47c13118bf19c7ce8d6f39includes mainb11c7bf84f5d2f636ff60166cc3371bd071e24d5and preserves previous public commits and attribution/licence notices. Retains the measured qsort_s bounds and safe zero-size host no-op policy, including the explicit PPSA07923 extreme-boundary SIGFPE caveat. Main’s separate reentrant helper block and qsort_r body are byte-identical; no native return is invented for the faulting row.Linux x86-64, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON: rebuilt actual libc/Ampr and selected executables.
guest_qsort,guest_bounds_checking,guest_safe_errors,guest_crteach pass 3/3 (12 runtime passes, zero skips);public_headers, conventions and whitespace checks pass. Pinned main passes all 17 selected baseline groups 3/3 (51 passes) plus headers. Before/after dependency checks agree: 34 recursive trees and 31,551 tracked blobs, zero errors; the update=none QuickJS test262 corpus is explicitly excluded from these library inputs.Source/parent/gitlink proofs, library/test hashes, raw logs/JUnit and head-leased push receipts: qualification archive, SHA-256
7c347f620951ad6f39068740750949212c6412815da094a46a96eca1d15c8bbf(download verified). Older platform, stress, negative-control and reference reports retain their original pins; no new Windows/macOS, full-suite, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).Earlier dated qualifications below retain their original source/platform pins.
Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release,
main319621ba2e.Native comparison: a scratch loader calls the titles'
qsort_sandbsearch_sby NID next to this build's, with the same recording handler on both sides. It runs 25 cases:n == 0with a null base or comparator;bsearch_s) a null key;2^61,2^62and2^63.Each case compares the return value, the array order or found element, and the handler's calls, error, pointer and message.
mainqsort_s(12 cases)n = 2^61bsearch_s(13 cases)Both titles give the same results.
Regression:
guest_qsort's constraint check expects the titles' message, and adds count and size cases at2^61(one withn == 0). With the previousFileAndHeap.cppit fails.Test set:
guest_qsort,guest_bounds_checking,guest_safe_errorsandguest_crtpass 3/3. Conventions pass.Current Linux qualification and native boundary limitation — 2026-10-29
Refreshed against main
5454cd2e455994d992aca39335ce60507eeda1eb. The refreshed #9688 head1c8ac1874c0ed5ccafef5112d59da6739d4a2fb6is an actual ancestor.Linux qualification at
d8bcdb2ce313bd8ceeb9ebdc67c02200bc3dedea(Arch Linux 7.2.9, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON):guest_qsort,guest_bounds_checking,guest_safe_errors,guest_crteach pass three consecutive runs (12/12, no skips). Thepublic_headersaudit passes at this exact head. All tracked public-header files match the pinned main; the affected test targets rebuild against those headers. Conventions and whitespace checks pass. The same focused groups passed three times on the pinned main.The restack preserves the existing safe zero-size no-op rule around the new parent sort interface. The original bundle qualifies historical head
d8bcdb2ce313; the following supplemental test/debt correction supersedes its extreme-count return-zero assertion.Narrowed the count-limit regression in
c6cfa7cfd9dbff57752dab24b5574af9d8037822. Thecount=SIZE_MAX>>3, size=0invocation remains, followed by the existing cumulative handler-count check, but it no longer asserts a native return of zero. That is a host constraint-guard check only. The separately measuredcount=1, size=SIZE_MAX>>3case still requires return0, and the handler-pointer checks remain. Production is unchanged.The new oracle evidence covers one existing PPSA07923 bundled module on Linux (unwrapped SHA-256
51ae8427c4a302abb1b6378fe65af69d4206d077006660eef4ee0e304e1e9e85). The size-limit/count-one case returns0 with no handler/comparator call and an unchanged canary. A rejectedcount=2^61,size=0control returns22 and calls the handler with the expected message, error22 and null pointer. The proposed count-limit/zero-size case instead faults with SIGFPE in original SDK integer division at module offset0x6a3cd. No returned value or handler/comparator/canary outcome was recorded for that faulting case, so none is inferred. The debt entry now records this mismatch with the unchanged safe host no-op policy.Linux Release, Ryzen9 7950X, GCC16.2.1:
guest_qsort,guest_bounds_checking,guest_safe_errorsandguest_crteach pass3runs (12 checks), plus thepublic_headersaudit (1), zero skips. Conventions and whitespace pass. This follow-up adds no new native execution; the separate oracle observations are not physical-console, Windows, PPSA05916 or other-SDK results. A question for review: is retaining this documented safe host no-op and scoping the extreme-count test to the constraint guard appropriate, given the observed SDK fault?AI-assisted: yes (Codex).
Evidence: current-head test/debt supplement, SHA-256
ad0c252cb06d3851b838e347f70967a7a7181c6603336af3adb242eb8c3f72be; sanitized native-oracle logs and identity proof, SHA-2568c5193f4cd7a2214932889221e3be6800f9ddf9d687153b3252d701b912bb1dd; original rebase qualification, SHA-25653b095da2f67f55b8aa56ba273681e0330fb39739be844458038dde410fb8cc4. No fresh Windows runtime is claimed here.Earlier qualification — 2026-10-30
Integrated current main
08a10d225306ad102b57408e2ef7566bcfb829b2into this existing topic at9125fed5190f6e1e14ec0ec96da721a6e4d256b6. Includes actual refreshed #9688 parentae15d0493797e9d40b2ab2eedbf202abf14c90e3. Current-main functions, fixtures, unrelated debt rows and exact dependency gitlinks are preserved; original topic functions and authored commits are retained. The documented PPSA07923 extreme zero-size SIGFPE observation and unchanged safe host no-op remain; the huge-count zero-size test invokes the call and checks the host handler guard without claiming an unsupported native return.Rebuilt actual Linux libc and focused test binaries.
guest_qsort,guest_bounds_checking,guest_safe_errors,guest_crteach passed three consecutive runs (12 runtime passes), pluspublic_headers; conventions and whitespace checks pass. Pinned main passed all seven selected runtime suites plus the header audit three times (24 runs). This is focused Linux CPU qualification; prior Windows/reference evidence retains its original pins. No new Windows, console, SDK-module, title, GPU or performance claim. AI-assisted: yes.Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math6-main08a10-linux-20261030.tar.gz (SHA-256 b984a6334dce65b5c9148e3791ba21605074a5e762ea0f07f96de2f38062ef6e).
Qualification update — 2026-10-30, repeat 2
Integrated pinned main
e471817c68d4e1b1e44b0ce369ed88bafe4ae8edat6fd92b781782253c45445523a3d00f44a38de7e0, retaining original topic commits as ancestors. Actual parent ancestry: #96881f001f3f23c74bf5dee00803644f2f17c82ac994. Main qsort_r retains its full FreeBSD helper/comparator behavior under private Reentrant-prefixed names; both sort implementations and every main qsort_r fixture are retained. Exact rename-normalized helper proof is attached. The PPSA07923 extreme-count zero-size SIGFPE debt caveat and unchanged safe host no-op are preserved; no unsupported native return is asserted.Actual Linux libc/focused binaries rebuilt from this final head;
guest_qsort,guest_bounds_checking,guest_safe_errors,guest_crteach pass three consecutive runs (12 runtime passes), plus public_headers. Conventions against current origin/main and whitespace pass. Pinned main passed all seven runtime groups plus the header audit three times (24 runs). Full source/function/test/debt/header and 31 recursive dependency / 17,742 tracked-blob proofs are attached. Later main1c6b316cf762has 17 off-topic commits, no relevant libc/numeric/qsort/gitlink changes, and all 9 merge previews are clean; those preview trees were not executed.Focused Linux CPU scope only: prior Windows/SDK/reference reports keep original pins. The Linux portion makes no fresh Windows, console, SDK-module, title/GPU or speed measurement is claimed by this report. AI-assisted: yes. Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math9-maine471-linux-20261030-repeat2.tar.gz (SHA256 5da4ce1732b45bb3fc566c31078c8c9ae8bf0c403654dfc60d15ee28490e20bf).
Actual Windows qualification at exact published
6fd92b781782253c45445523a3d00f44a38de7e0: Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2 UCRT r7, Ninja Release, BUILD_TESTING=ON. Rebuilt patched libc and guest_qsort_tests, then ran guest_qsort three times: 3/3 passes, zero skips. This checks the composed main qsort_r and branch sorting fixtures at the recorded head; no timing, SDK/game/GPU/console/macOS claim. Raw build/CTest/JUnit logs, DLL digest and terminal Windows FIFO receipt are included in https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-current-windows-20261030-repeat2.tar.gz, SHA256 e423c97373758bf59239e02c138b74f35f1a45488793bc92878a4c836f94a584. AI-assisted: yes (Codex).AI-assisted: yes (Codex).
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)ae15d0493797e9d40b2ab2eedbf202abf14c90e3remains an ancestor, and the measured boundary limits and documented safe host no-op remain)