Repository navigation
With a data file, CopyFrom stores a file at the size its source declared, and refuses one that reads short - #310
Open
closer-claudio wants to merge 1 commit into
Open
closer-claudio wants to merge 1 commit into
closer-claudio wants to merge 1 commit into
Conversation
With a data file, CopyFrom read a regular file to the end of its reader and recorded what it had read as the file's size. Without one, Close stops at the size the source declared and fails on a short read. The two stored different files from one source: a file declared 10 bytes that read as a megabyte was 10 bytes in the image and 1048576 with a data file, all of them written to it, and a reader that never ended filled the data file. A file that read shorter than it declared was stored short, without an error. CopyFrom now reads the declared size and no more into the data file, and fails with io.ErrUnexpectedEOF on a file that ends before it, as Close does without a data file. mkfs.erofs copies the size it found the file with and fails on fewer (lib/inode.c, erofs_write_unencoded_file: i_size is st_size, and a tail read short of it is -EIO), read and not run. The other reader a copy stores in a data file, a holed file's data laid out by chunks, is this package's own, over an image's ranges, and bounded by them: no source hands one. TestContractCopiedFileIsTheSizeItsSourceDeclared, with a data file and without: a file that reads a megabyte where it declared ten bytes is ten bytes, and the data file holds no more than a block of it; one that reads none, four or nine of its ten bytes fails with io.ErrUnexpectedEOF, in CopyFrom with a data file and at Close without. With a data file the first, the second and the size of the data file fail before the change. With the read not bounded, the short read not refused, or one byte short allowed, the test fails. For #272 Signed-off-by: closer-claudio <claudio@farcloser.world> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
closer-claudio
enabled auto-merge
November 23, 2026 17:46
Author
|
Reviewed at ae5792c |
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 defect
With a data file,
CopyFromread a regular file to the end of its reader and recorded what it had read as the file's size. Without one,Closestops at the size the source declared and fails on a short read. The two stored different files from one source:The change
CopyFromreads the declared size and no more into the data file, and fails withio.ErrUnexpectedEOFon a file that ends before it, asClosedoes without a data file.mkfs.erofscopies the size it found the file with and fails on fewer bytes (lib/inode.c,erofs_write_unencoded_file:i_sizeisst_size, and a tail read short of it is-EIO). Read from the source, not run.The other reader a copy stores in a data file, a holed file's data laid out by chunks, is this package's own, over an image's ranges, and bounded by them: no source hands one.
What a consumer sees
With a data file:
CopyFromwithio.ErrUnexpectedEOF, where it was stored short.Nothing changes without a data file, nor for a source whose files read the size they declare.
Evidence
TestContractCopiedFileIsTheSizeItsSourceDeclared, with a data file and without: a file that reads a megabyte where it declared ten bytes is ten bytes, and the data file holds no more than a block of it; one that reads none, four or nine of its ten bytes fails withio.ErrUnexpectedEOF, inCopyFromwith a data file and atClosewithout. With a data file three of these fail before the change.With the read not bounded, the short read not refused, or one byte short allowed, the test fails.
just lintandjust testpass.For #272
Not changed here: after a
CopyFromthat failed part of the way,Closewrites what was copied until then and returns nil, and with a data file that image can be corrupt. A file that reads short now takes that path, where before it was stored short with no error: #309.