Skip to content

Fix incorrect inputOffset after Skip with seeker#37

Open
mhr3 wants to merge 1 commit intophilhofer:masterfrom
mhr3:fix-skip-seek-input-offset
Open

Fix incorrect inputOffset after Skip with seeker#37
mhr3 wants to merge 1 commit intophilhofer:masterfrom
mhr3:fix-skip-seek-input-offset

Conversation

@mhr3
Copy link
Copy Markdown
Contributor

@mhr3 mhr3 commented Mar 25, 2026

Summary

  • Fix bug in Reader.Skip: Seek returns the new absolute position in the stream, not the number of bytes moved. The code was treating the return value as a delta, causing inputOffset and the returned skip count to be wrong whenever the underlying stream position was non-zero (i.e. after any prior reads).
  • Use the known seek delta (n - skipped) directly instead of the absolute position returned by Seek. Also properly handle Seek errors by returning early before updating inputOffset.
  • Add TestSkipSeekInputOffset that exercises the bug scenario: reads bytes first to advance the stream, then skips with seek, and verifies InputOffset() and data correctness.

Test plan

  • New TestSkipSeekInputOffset verifies correct offset tracking after read + seek-skip
  • Existing TestSkipSeek and TestInputOffset continue to pass
  • Full test suite passes

Made with Cursor

Seek returns the new absolute position, not the number of bytes moved.
The code was treating the return value as a delta, which caused
inputOffset and the returned skip count to be wrong whenever the
underlying stream was not at position 0 (i.e. after any prior reads).

Use the known seek delta (n - skipped) directly instead of the absolute
position returned by Seek.

Made-with: Cursor
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.

1 participant