Repository navigation
fix: store LongBits words unsigned - #212
Merged
Merged
Conversation
LongBits stores lo as lo | 0. For values with hi == 0 and lo in [2^31, 2^32) that is negative, so writeVarint64 writes one byte into the 5 bytes length() reserved and leaves 4 bytes of the allocUnsafe slab unwritten. uint64 and int64 are affected. sint64 and fixed64 are not. protobufjs stores both words with >>> 0. The port in d101804 changed them to | 0. Restore >>> 0 and add a regression test at the window edges.
SgtPooki
force-pushed
the
fix/longbits-unsigned-words
branch
from
October 15, 2026 12:42
42af6a1 to
8282f66
Compare
SgtPooki
marked this pull request as ready for review
October 15, 2026 12:47
Member
Author
|
@wemeetagain @achingbrain can we get this in ASAP? two-line fix with test included. every 2 to 4 GiB file written through ipfs-unixfs since 2023-10-13 has a root node Go can't read. |
Member
Author
|
other callers of
so this isn't only a unixfs problem. |
hugomrdias
added a commit
to filecoin-project/agents
that referenced
this pull request
Oct 15, 2026
…files protons-runtime 5.0.4 through 8.0.1 encodes uint64 values in [2^31, 2^32) as one varint byte plus four bytes of stale Buffer pool memory (ipfs/protons#212). packDirectory wrote a corrupt file-root node for any 2–4 GiB file in a folder: the root CID changed between runs and extractCar failed with "invalid wire type". No fixed release is on npm, so patch protons-runtime 6.0.2 (importer) and 8.0.1 (exporter) with the upstream one-line fix. Add a regression test that builds a 3 GiB file root from fake leaves, and document that folders stored with filecoin 0.5.0 or earlier holding such a file must be stored again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Looks like publishing to npm failed here. |
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.
LongBitsstores its low word signed (this.lo = lo | 0). For a 64-bit value withhi == 0andloin[2^31, 2^32)the word is negative, sowriteVarint64writes one byte into the 5 byteslength()reserved. The other 4 bytes are whatever was in theallocUnsafeslab.uint64,int64sint64,fixed64,sfixed64Repro
Without
--zero-fill-buffersthe 4 bytes are Buffer pool leftovers, so the same node encodes differently depending on what ran before it. Browser builds ofuint8arrayszero-fill, so there it is always the0000000000form.Impact
UnixFS
filesizeandblocksizesare uint64. A file node is invalid protobuf when itsfilesizeor anyblocksizesentry is in[2^31, 2^32). That is every multi-block file of 2 GiB to 4 GiB, plus larger files with a subtree in that range.proto: cannot parse invalid wire-format dataon the zero form, or decodes wrong values (filesize 0) when the leftovers happen to parseaddof a 2 to 4 GiB file produces a UnixFS root Kubo cannot parse (protons-runtime uint64 bug) filecoin-project/filecoin-pin#773Where it came from
>>> 0(src/util/longbits.js#L23-L29 at protobufjs-v7.2.5, the line 5.0.3 wrapped); the port changed them to| 0mainbroken (bisected, then each major checked from npm)^5.0.0) break on any install after 2023-10-13; 11.1.4 and later (^5.4.0,^5.5.0,^6.0.1,^7.0.0,^7.1.1,^8.0.1) have never resolved to a working runtime; a lockfile pinned to 5.0.3 is fineChange
Restore
>>> 0on both words. Regression test at the window edges foruint64andint64, red onmain, green here.Checked 13,483 encodings across all five 64-bit codecs before and after: the 520 in-window cases change to the correct bytes, nothing else moves.
INT64_MINis mis-encoded onint64/sint64/sfixed64both before and after; separate overflow infromBigInt, not touched here.fixes #213