Repository navigation
fix(io): avoid allocating the entire file prefix limit - #10545
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the bounded 4 KiB read loop and test coverage for empty/short files, chunk boundaries, maximum valid stream size, UTF-8 paths, missing files, directories, invalid limits, and Linux proc files with zero reported size. The loop stops on short reads without depending on file size and preserves the existing bad-stream error. I built and ran the exact PR-head test directly with GCC 12 (-std=c++20 -Wall -Wextra -Werror): File prefix-read tests passed. Hosted eligibility, conventions, intake, labels, Linux/Windows/macOS relinker builds, and ASAN pass; unrelated platform build jobs were skipped by eligibility.
roboterspinne
left a comment
There was a problem hiding this comment.
Reviewed head 4866d9e merged onto upstream/main 63a863d (2026-10-25); the merge is clean.
Environment: Windows 11 Home 10.0.26200, Intel i9-12900H, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release.
Results
- Full relinker-only suite on the merged tree: 262 tests, 260 pass,
long_pathsskipped. The one failure ispatch_advisor_unit. It fails the same way on plainmainon this machine, because the temp path contains a space (#10667), and it is unrelated.file_reader_prefixpasses. - Counter-check: with
main'sFileReader.cppunder this test,file_reader_testsexits 1 withstd::bad_alloc. With this branch it printsFile prefix-read tests passed.- Only the
maximumlimit is red onmain. With that one limit removed, the test passes onmain, so the other cases are regression coverage for the new loop. - Those cases catch real mistakes in the loop. Always stopping after the first chunk fails at limit 4097. Requesting a whole chunk regardless of the limit fails at limit 1, and so does inserting
requestedinstead ofcount. Opening the stream withoutstd::ios::binaryfails at 4095, because the fill pattern covers all 256 byte values, 0x1A included.
- Only the
- The new loop returns the same bytes as the old single
read. In GCC 15.2's libstdc++,basic_filebuf::xsgetnkeeps reading until end of file or an error (bits/fstream.tcc:717-731). Socount < requestedonly happens at EOF or withbadbitset, and an error after a partial chunk still throwsCannot read file: <path>. For every limit up to 4096, it is the same singlereadcall as before. ReadPrefixhas one production caller onmain,main.cpp:44. It reads 0x40 bytes for the ELF magic check and makes the same singlereadas before. So nothing changes for users today; the PR removes a latentbad_allocfrom the API.check_conventions.py --base upstream/mainpasses with this title and body. Hosted relinker jobs (ubuntu, windows, macOS) are green on 4866d9e.
Notes, nothing to change here
- The overlap paragraph is slightly out of date. #6044 has been closed since. Two open PRs on the same files are not named: your #10303, which adds
native_path_teststo the sameCMakeLists.txt, and #9711, which changes theinput_magicregistration that covers the only caller. Both merge cleanly with this PR. - The Linux
/proc/self/cmdlinecase usesfile_size == 0as a hard precondition, so it would fail rather than skip if a sandboxed/procever behaved differently.
Not checked: Linux and macOS locally (the /proc case is compiled out on Windows; it ran in the hosted ubuntu job).
I found nothing to change: the chunked loop keeps the old results and diagnostics for every limit, and the test pins the fix and the loop's edges. For disclosure: I have open relinker PRs, and three of them (#10732, #10646, #10402) also touch core/relinker/CMakeLists.txt; each merges cleanly with this one.
Written with AI assistance (Claude Code). I ran the build, the tests and the counter-check above on my Windows 11 machine.
What
std::bad_alloc.file_size, since regular proc files can report zero while still containing readable data./proc/self/cmdlinewith its zero reported file size.Tested
std::bad_allocfor an empty file and the maximum valid prefix limit. It passes with this fix.ctest --test-dir build-relinker --output-on-failure --parallel 4).file_reader_prefix,input_magic,input_file, andinput_nonascii: five consecutive passes each (--repeat until-fail:5).-Wall -Wextra -Werror, five successful runs each. Sanitizers usedetect_leaks=1:halt_on_error=1andhalt_on_error=1:print_stacktrace=1.file_reader_prefixpasses five consecutive CTest runs. Thetest_input_magic.py,test_input_file.py, andtest_input_nonascii.pyCLI integration scripts also pass, using native Linux temporary storage.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.python tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch fix/file-prefix-allocation --jobs 4found no competing prefix-reader implementation. It could not automatically compare the shared CMake file against already-conflicted PRs feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, test: organize library tests and label CTest suites #6044, and feat(relinker): trace function imports on macOS #9408. Manually reviewed their CMake patches: they add macOS fixtures, migrate existing registrations to component tests, and add macOS trace-import tests, respectively. None changesReadPrefixor adds the new reader test target.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)