Repository navigation
Description
encode_data_frame writes the payload length with an unchecked cast, (payload.len() as u32) (fluree-db-core/src/pack.rs:233), and then appends the whole payload (:234). So for a CAS object of 4 GiB or more, the length field wraps (it becomes len mod 2^32) while all len bytes still go into the stream. Nothing upstream checks first, either: the archive producer reads each object and hands it straight to the encoder (fluree-db-api/src/pack.rs:540-553 for index artifacts, and likewise :338, :470 and :508 for the default context, commits and txn blobs).
The export reports success, and the problem only shows up when something reads the pack back. The reader takes the wrapped length at face value (decode_data_frame, pack.rs:348-362), so it either slices off a short payload that then fails the CID check (integrity check failed for <cid>, fluree-db-api/src/commit_transfer.rs:144-148), or, if the wrapped length happens to land above the cap, fails with payload too large quoting a size that isn't the object's real one. Either way the restore fails and rolls back after it has already streamed and written everything before that frame.
So I don't think this is silent data corruption (SHA-256 verification catches it, which is the important saving grace here), but it is a silently corrupt artifact: the step that wrote the pack says it worked, and the failure surfaces later, often on another machine, with an error that points nowhere near the cause.
The header, error and manifest encoders have the same cast (pack.rs:219, :241, :249). Those carry JSON or a message, so I don't think they can realistically get there, but they'd share the fix.
How you'd get there. As far as I can tell, the only object that can grow this large today is a per-predicate xsd:decimal arena, which keeps every distinct decimal of one predicate in a single object, so this needs somewhere around 180-200M distinct decimals on one predicate. That's its own scaling problem, and the 1 GiB restore cap bites much earlier (#2417). Everything else I looked at is either bounded well below 4 GiB (forward dict packs target 16 MiB, fluree-db-binary-index/src/dict/pack_builder.rs:33) or scales with import chunk size rather than with the ledger. So it's latent, but it's the kind of latent where the first person to hit it loses an export they thought they had.
Proposal
- One shared
checked_frame_len(usize) -> PackResult<u32>(with a newPackErrorvariant that names the CID and the size), and theencode_*_framefunctions returnPackResult<()>, so an oversized object fails the export instead of writing a bad length. The callers are the four sites influree-db-api/src/pack.rsplus tests. - No format change. v1 can't describe a frame of 4 GiB or more, and I don't think it needs to while nothing legitimately produces one. If we ever want that, a v2 preamble with a
u64frame length, written only when needed, seems like the clean path, since old readers already refuse an unknown version cleanly (read_stream_preamble,pack.rs:272-275).
Test. checked_frame_len can be unit-tested at u32::MAX as usize and u32::MAX as usize + 1 without allocating anything, so I don't think we need a 4 GiB fixture for this.
(The arena's own handle counter, self.values.len() as u32 in fluree-db-binary-index/src/arena/numbig.rs:185, has the same unchecked shape, but it would only wrap past ~4.29B distinct values on one predicate, long after this one does, so I've left it out.)
Found while scoping large-pack limits with Claude; anchors are on main at beb851f30 (read, not run).
Activity
fix(cli,python): a failed .flpack archive removes its partial file on…