Skip to content

Correct SpooledStringIO end-relative seek offsets - #543

Closed
theman6660 wants to merge 1 commit into
mahmoud:masterfrom
theman6660:codex/fix-spooledstringio-end-offsets
Closed

theman6660 wants to merge 1 commit into
mahmoud:masterfrom
theman6660:codex/fix-spooledstringio-end-offsets

Conversation

@theman6660

Copy link
Copy Markdown

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:

  • Original code: 54 failing and 8 passing subtests in the new regression tests.
  • Complete source suite and module doctests: 682 tests and 74 subtests passed.
  • Built and installed wheel outside the checkout, with its import path verified: 682 tests and 74 subtests passed.
  • 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

  • Harness/tooling: OpenAI Codex desktop; source inspection, implementation, tests, validation and this description were prepared with Codex assistance under the contributor's authorization.
  • Model(s): GPT-6-based Codex; exact serving-model identifier unavailable.
  • Original prompt, verbatim: “去多做几个” (“Go make a few more”), following the contributor's request to continue GitHub PR contributions.

@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Folded into #609 (see the PR description for credit). Thanks for the report and the repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants