fix(mantaray): tolerate bee's ref_size = 0 wire form on decode#35
Merged
Conversation
bee occasionally emits manifest nodes with `ref_size = 0` for entry-less terminal nodes (mantaray-js documents this with an explicit FIXME: "in Bee, if one uploads a file on the bzz endpoint, the node under `/` gets 0 refsize"). Per the spec and every reference impl, `ref_size` is a uniform per-node width governing both the entry slot and every fork ref slot; the only legal values are `E::SIZE` (32 plain / 64 encrypted). Accept `ref_size = 0` only when the forks bitfield is also empty (the terminal-node case the bee artifact represents). Reject `ref_size = 0` with non-empty forks as malformed rather than silently dropping forks the way bee's v0.2 decoder does at marshal.go:285-287 — no impl can coherently round-trip fork refs at zero width. The encoder is unchanged: it continues to emit `ref_size = E::SIZE` with zero entry bytes for entry-less nodes, matching bee's own "valid manifest" test fixture and mantaray-js. Reproducing the bee bug on the write side would defeat the purpose. Adds four regression tests pinning the v0.1 and v0.2 decoder behaviour and the encoder's spec-correct output.
ed01900 to
17cf7d5
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What does this PR do?
Tolerates bee's
ref_size = 0mantaray wire form on decode so nectar can read real-world bee-produced manifests.Changes
decode_empty_terminal_nodeto handleref_size = 0; invoked from bothdecode_v01anddecode_v02. Accepts the shape only when the forks bitfield is empty; rejectsref_size = 0with non-empty forks as malformed.BEE-WORKAROUND(bee#5483). Documents the convention incrates/mantaray/src/lib.rsso future maintainers can enumerate sites withgit grep -n BEE-WORKAROUNDonce the upstream bee fix has propagated.ref_size = 0plus non-empty forks; an encoder pin asserting nectar never emitsref_size = 0.Breaking changes
None. The encoder is unchanged; the decoder strictly broadens what it accepts.
Testing
nectar-mantaray --lib, 4 of them new)Related issues
AI assistance disclosure
AI Assistance: Claude Code used for the architectural review (parallel agents reading bee Go, nectar Rust, and the spec / mantaray-js reference), drafting the patch, writing tests, and authoring this PR description.
Notes for reviewers
ref_sizegoverns both entry slot and every fork ref slot) is what the bee spec doc (bee/pkg/manifest/mantaray/docs/format/node.md) and every reference impl (bee, mantaray-js, nectar) say; the HAZMAT block abovedecode_empty_terminal_nodecaptures the context.ref_size = 0errors out rather than silently dropping forks like bee's v0.2 reader does.Checklist