Repository navigation
Conversation
|
The following commit authors need to sign the Contributor License Agreement: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_io.BufferedRandom.truncate()rewinds the raw stream and resets the read bufferbefore truncating (
buffered_flush_and_rewind_unlocked()inModules/_io/bufferedio.c)._pyiodoes not, although the comment there alreadysays "Use seek to flush the read buffer", so a read after
truncate()can returndata that is no longer in the file:
The one-line
self.seek(self.tell())keeps the logical position unchanged (astruncate()must) while rewinding the raw stream and emptying the read buffer, whichis what
_iodoes.Tested: the reproducer and the new test were run against
_io, against unpatched_pyioand against patched_pyioon 3.13 (the touched code is byte-identical onmain), plus a 25-case differential battery overr+b/ab+/w+band truncationpoints 0/1/3/None comparing return value,
tell(), followingread()and theresulting file size: 12 divergences from
_iobefore, 0 after. I have not run thefull
test_iosuite locally (no local build yet), so CI is the check for that._pyio.BufferedRandom.truncate()keeps the read buffer, so later reads return data that is no longer in the file #161271