Skip to content

fix: return ErrUnexpectedEOF on short copies#23

Merged
hayabusa-cloud merged 2 commits intomainfrom
fix
Feb 26, 2026
Merged

fix: return ErrUnexpectedEOF on short copies#23
hayabusa-cloud merged 2 commits intomainfrom
fix

Conversation

@hayabusa-cloud
Copy link
Copy Markdown
Owner

Summary

  • CopyNPolicy and CopyNBufferPolicy returned (written, nil) on short copies instead of (written, io.ErrUnexpectedEOF), diverging from the CopyN/CopyNBuffer contract.
    • Solution: Add the same written < n post-check after copyBufferPolicy returns.
  • Fix copyBufferPolicy slow-path write loop to check IsSemantic(ew) with rollbackSeeker before the bare return.
  • Update two tests to assert the corrected io.ErrUnexpectedEOF behavior.

Copilot AI review requested due to automatic review settings February 26, 2026 11:42
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
io.go 86.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical bug where CopyNPolicy and CopyNBufferPolicy violated the CopyN contract by returning (written, nil) instead of (written, io.ErrUnexpectedEOF) when unable to copy the requested n bytes. The fix also adds defensive handling for wrapped semantic errors in the write loop.

Changes:

  • Added post-copy validation in CopyNPolicy and CopyNBufferPolicy to return io.ErrUnexpectedEOF when written < n and the error is nil or EOF
  • Added rollback handling for wrapped semantic errors in copyBufferPolicy write loop
  • Updated test expectations to assert the corrected io.ErrUnexpectedEOF behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
io.go Fixed CopyNPolicy and CopyNBufferPolicy to return io.ErrUnexpectedEOF on short copies; added defensive rollback for wrapped semantic errors in copyBufferPolicy
policy_test.go Updated test names and assertions to expect io.ErrUnexpectedEOF on short copies

@hayabusa-cloud hayabusa-cloud merged commit a37d5e5 into main Feb 26, 2026
4 of 5 checks passed
@hayabusa-cloud hayabusa-cloud deleted the fix branch February 26, 2026 12:03
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