Skip to content

fix(mantaray): tolerate bee's ref_size = 0 wire form on decode#35

Merged
mfw78 merged 1 commit into
mainfrom
fix/mantaray-ref-size-zero
Jun 1, 2026
Merged

fix(mantaray): tolerate bee's ref_size = 0 wire form on decode#35
mfw78 merged 1 commit into
mainfrom
fix/mantaray-ref-size-zero

Conversation

@mfw78

@mfw78 mfw78 commented Jun 1, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Tolerates bee's ref_size = 0 mantaray wire form on decode so nectar can read real-world bee-produced manifests.

Changes

  • Add decode_empty_terminal_node to handle ref_size = 0; invoked from both decode_v01 and decode_v02. Accepts the shape only when the forks bitfield is empty; rejects ref_size = 0 with non-empty forks as malformed.
  • Tag every tolerance site with grep-able BEE-WORKAROUND(bee#5483). Documents the convention in crates/mantaray/src/lib.rs so future maintainers can enumerate sites with git grep -n BEE-WORKAROUND once the upstream bee fix has propagated.
  • Four new regression tests: empty terminal node decode for v0.1 and v0.2; rejection of ref_size = 0 plus non-empty forks; an encoder pin asserting nectar never emits ref_size = 0.

Breaking changes

None. The encoder is unchanged; the decoder strictly broadens what it accepts.

Testing

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

  • The uniform-ref-width rule (ref_size governs 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 above decode_empty_terminal_node captures the context.
  • Decode tolerance is bounded: only the empty-forks-bitfield case. Anything else with ref_size = 0 errors out rather than silently dropping forks like bee's v0.2 reader does.

Checklist

  • Code follows project style
  • Self-review completed
  • Tests added (4 new regression tests)
  • No debug code left behind
  • PR title is descriptive

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.
@mfw78 mfw78 force-pushed the fix/mantaray-ref-size-zero branch from ed01900 to 17cf7d5 Compare June 1, 2026 07:41
@mfw78 mfw78 merged commit bafa3ac into main Jun 1, 2026
4 checks passed
@mfw78 mfw78 deleted the fix/mantaray-ref-size-zero branch June 1, 2026 07:48
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Mantaray decoder rejects bee-emitted ref_size = 0 empty terminal nodes

1 participant