Repository navigation
Correct SpooledStringIO end-relative seek offsets - #543
Closed
theman6660 wants to merge 1 commit into
Closed
theman6660 wants to merge 1 commit into
theman6660 wants to merge 1 commit into
Conversation
Owner
|
Folded into #609 (see the PR description for credit). Thanks for the report and the repro. |
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.
The change
SpooledStringIO.seek(offset, os.SEEK_END)subtracts the offset instead of adding it. After writing'abcde',seek(-2, SEEK_END)currently reports position 7 and returns no data; it should seek to position 3 and leave'de'to read. Positive offsets move backwards instead of beyond the end, and can produce a negative logical position on an empty stream.Calculate the destination as the character length plus the offset, then reuse absolute character seeking. Reject destinations before zero consistently with this class's existing absolute/current-relative seeks, restoring the original position before raising. Both in-memory and rolled streams use the same code path.
Tests cover negative/zero/positive offsets, ASCII and multibyte Unicode, empty and newline-containing streams, positions beyond EOF, invalid destinations with position preservation, and traversal across a read-chunk boundary.
This is separate from #527, which preserves the cursor for external length queries. This patch only changes end-relative seek handling and is independently based on upstream master.
Validation on Windows / Python 3.12.10:
git diff --check: passed.Other interpreters and operating systems were not tested locally.
The backstory
Previous contribution: #519, which contains my contribution background. This was found while checking file-like operations against their documented character positions during a contribution-oriented source inspection; it was not observed in production.
AI assistance