Skip to content

Conversation

@Kubuxu
Copy link
Contributor

@Kubuxu Kubuxu commented Aug 20, 2025

BlockReader.NextReader facilities reading larger blocks from the CAR file.

This is necessary for the support of the Filecoin snapshot format extension (FRC-108, lotus issue), where a large block is used to transfer data about F3.

BlockReader.NextReader facilities reading larger blocks from the CAR
file.

Signed-off-by: Jakub Sztandera <[email protected]>
@BigLep BigLep moved this to 🔎 Awaiting Review in nv27 Track Board Aug 20, 2025
@BigLep BigLep moved this to Todo in F3 Aug 20, 2025
@BigLep BigLep added this to F3 Aug 20, 2025
@BigLep BigLep moved this from Todo to In review in F3 Aug 20, 2025
Comment on lines 52 to 54
if size > math.MaxInt64 {
return cid.Cid{}, 0, ErrHeaderTooLarge
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if size > math.MaxInt64 {
return cid.Cid{}, 0, ErrHeaderTooLarge
}

this is unnecessary, it's what LdReadSize does with its third arg for you to generate a uniform error pattern

Copy link
Member

Choose a reason for hiding this comment

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

also if this really is necessary, ErrSectionTooLarge cause this isn't actually a header.

Copy link
Contributor Author

@Kubuxu Kubuxu Aug 21, 2025

Choose a reason for hiding this comment

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

Added this because the int64 cast for LimitReader (don't want to cast to negatives)

// on the BlockReader.
// The returned length might be larger than MaxAllowedSectionSize, it is up to the user to check before loading the data into memory.
func (br *BlockReader) NextReader() (cid.Cid, io.Reader, uint64, error) {
c, length, err := util.ReadNodeHeader(br.r, br.opts.ZeroLengthSectionAsEOF, math.MaxUint64)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
c, length, err := util.ReadNodeHeader(br.r, br.opts.ZeroLengthSectionAsEOF, math.MaxUint64)
c, length, err := util.ReadNodeHeader(br.r, br.opts.ZeroLengthSectionAsEOF, math.MaxInt64)

Or is there a reason you're using MaxUint64 but then capping it at MaxInt64 inside ReadNodeHeader? Why not just use MaxInt64 all the way through.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the maxsize param is uint64 everywhere, so from an external API viewpoint, I'm passing unlimited (maximum allowed value). Then the function internally caps to what it is able to handle.

Both perspectives make sense though

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

sure, except for the maxuint vs maxint question

This was referenced Aug 21, 2025
Signed-off-by: Jakub Sztandera <[email protected]>
@BigLep
Copy link
Contributor

BigLep commented Aug 21, 2025

@rvagg : will you be ok to merge and cut a release at your convenience as filecoin-project/lotus#13129 will be depending on it (being worked on next week).

@rvagg rvagg merged commit 08a8582 into master Aug 22, 2025
17 checks passed
@rvagg rvagg deleted the feat/next-reader branch August 22, 2025 00:05
@github-project-automation github-project-automation bot moved this from In review to Done in F3 Aug 22, 2025
@github-project-automation github-project-automation bot moved this from 🔎 Awaiting Review to 🎉 Done in nv27 Track Board Aug 22, 2025
@rvagg
Copy link
Member

rvagg commented Aug 22, 2025

Just noting here for completeness for anyone looking on afterwards (probably should have noted in code) - in this PR we're bypassing some byte buffer size limitations we put in place to deal with security concerns a while a go, essentially saying "a section can be unlimited size, I don't even care what size the CID is" - but this is OK here because, (a) obviously we're doing an io.Reader and not buffering, it's up to the downstream user to take appropriate actions to limit buffering of blocks (again, probably worth documenting), and (b) the place where we do buffer, in the CID decoding, has a limit in place internally and won't accept sizes above 32MiB.

But, the important point here is that a CAR section head could claim that the section is a certain size and lie about it, forcing an implementation to allocate way too much memory, significantly larger than the CAR itself.

rvagg added a commit to filecoin-project/lotus that referenced this pull request Aug 22, 2025
rvagg added a commit to filecoin-project/lotus that referenced this pull request Aug 25, 2025
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.

4 participants