fix(libc): discard pushback bookkeeping when reopening a stream #27494
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27494"
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-11-26T14:41:28Z.
What
After
ungetcon a stream,freopenreplaces the native handle but leaves the wrapper's narrow pushback bookkeeping live. A subsequentfpurgecan restore a byte from the old file into the reopened stream. Clear that bookkeeping inFileStream::Adopt, alongside the other per-handle resets. The regression reopens a file containingnewand requiresfpurgefollowed byfreadto return those three bytes.This follows the reset of the old pushback buffer in FreeBSD 11.4 freopen; no reference source code is copied. This fixes main independently of the close-all/alias work in #11831.
Tested
2026-11-26, Linux 7.3.5-arch1-1 x86-64, GCC 16.2.1, Release. Base
af6a58c4d30bbc8901b5855081002cd965254b7c; head2b1eec1ddd570840d07439af97d489703e0391a0. Fresh independent source/build with 49 verified submodules and newly built raw libc/kernel providers.51455729e9b009f4e22968fcdc6a10b0928480fd48f219d0cad145dae4d68d54) passes with the fixed provider and aborts atreopen discards the previous stream's pushbackwith the preserved main provider. Main production source is unchanged in that control; only the identical fixture was added. Actual provider initialization paths are checked withLD_DEBUG;ldd -ris clean.Patch, fixture, build/test logs, JUnit, loader records and hashes, SHA-256
7e86831b25bee09b61673d8ddd1566a84c0614cd4d30024ccd29a7a36fa75a75; anonymous download and all 33 payload hashes verified.Before implementation, the export lookup found #11831 plus two library-split PRs for
freopen, and #11831 forfpurge. The full branch scan examined 2,407 open PRs but failed closed on seven conflicting branches. I manually compared their sharedFileStream.hpppatches andAdoptbodies at the pinned heads in the archive: #7447, #11831, #12682, #12688, #12700, #12965 and #24406. None contains this newer narrow-pushback bookkeeping or its reset; their archive, lifetime, descriptor-locking and bad-descriptor changes are separate. This is a manual source disposition, not clean full-branch composition or runtime qualification of those PRs.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T14:52:45Z.
Review: APPROVED
Reviewed — looks good
The reviewed change resets wrapper pushback bookkeeping when a stream adopts a replacement handle, and the focused regression covers reopening, purging, and reading the replacement contents.
What I ran
Read the prepared diff and both changed files at head
2b1eec1ddd570840d07439af97d489703e0391a0usingrepo_read.py. No build or tests were run during this review; test results in the PR description are author reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run during this review. The PR description reports focused Linux CTest and regression-control results, but those were not independently verified here. No other changed files were excluded; both files listed in the manifest as reviewed were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:12:26Z.
Review: COMMENTED
Built and ran
guest_stream_purgeon Linux with this head integrated. The suite passed. The added test pushes a byte back on the old stream, reopens it on a second file, and checks that purging leaves only the second file's bytes.FileStream::Adoptnow clears the pushback state alongside its other per-handle resets.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.