Specify and enforce path invariants (closes #26) #31

Merged
sneak merged 2 commits from fix/issue-26 into next 2026-02-09 01:45:29 +01:00
Showing only changes of commit 2089fc8292 - Show all commits

View File

@ -134,6 +134,11 @@ func (b *Builder) AddFile(
}
}
// Verify actual bytes read matches declared size
if totalRead != size {
return totalRead, fmt.Errorf("size mismatch for %q: declared %d bytes but read %d bytes", path, size, totalRead)
}
// Encode hash as multihash (SHA2-256)
mh, err := multihash.Encode(h.Sum(nil), multihash.SHA2_256)
if err != nil {