Bounty
XE-13401 · Bounty

DecodeVote panics on a crafted vote encoding: uint16 length wraparound at core/encoding.go:699

Closed · duplicate —claimed Minor xe#563 filed 2026-11-14 19:23 UTC by Aurora Belle

Report

Severity: Minor (XE tier ceiling 650 XE). No CVSS vector is asserted: there is no attacker-reachable trigger at HEAD (see §5), so a CVSS score would imply an exploitability the evidence does not support. See §7 for the severity reasoning.

Target: github.com/xeprotocol/xe @ 89a542ea51d38375299aee54c6c99102e9bfa666 ("release: testnet-0005 quorum withhold fix", 2026-11-10). Go 1.25.4.

1. Impact (read this first)

core.DecodeVote — the exported decoder for the canonical binary vote encoding — panics (runtime error: slice bounds out of range [140:139]) on a well-formed vote encoding whose signature is 65,396–65,535 bytes long. The panic is deterministic, needs no mutation luck: a boundary seed (a vote with a 65,535-byte signature, built through the production EncodeVote) crashes it on first call.

The honest bound, stated up front: at HEAD this function has no in-repo callers — votes travel as JSON (net/messages.go VoteMsg), and DecodeVote is called from nowhere in xe/, sdk/, or dao/ (verified by repo-wide grep, §6). So today this is a latent panic in an exported decoder, not a live remote node crash. Its value is as a hardening fix: the function is the public decoder for the consensus vote format, and any future caller — a binary vote wire path, a future votesync, out-of-tree tooling — inherits a deterministic panic on a ~64 KiB input. The fix is one word (§8). The committee may reasonably close this as informational; the draft does not inflate it beyond Minor.

2. Root cause

core/encoding.go:693 reads the signature length as uint16:

sigLen := binary.BigEndian.Uint16(data[138:140])
if len(data) < 140+int(sigLen) {   // line 694: INT arithmetic — correct
    return nil, fmt.Errorf("DecodeVote: data truncated: ...")
}

sig := make([]byte, sigLen)
copy(sig, data[140:140+sigLen])   // line 699: UINT16 arithmetic — wraps

Line 694 guards with int arithmetic, but line 699 slices with uint16 arithmetic. In Go, 140+sigLen with sigLen uint16 is computed in uint16: for sigLen in (65395, 65535], 140+sigLen exceeds 65535 and wraps modulo 65536. For sigLen = 65535: 140+65535 = 65675 → wraps to 139, so the slice becomes data[140:139] and panics. The guard passes because the input really is long enough (len(data) = 65675 = 140+65535); the guard and the slice disagree about the arithmetic, and the slice is the one that is wrong.

The same file's sibling encoder has the matching latent shape: EncodeVote (encoding.go:659) does sigLen := uint16(len(v.Signature)), silently truncating any signature longer than 65,535 bytes before writing the length — harmless in practice (real signatures are 64 bytes) but the same class of unchecked narrowing.

3. Scenario (how it happens)

  1. A caller passes attacker-influenced bytes to DecodeVote — today no such caller exists in-repo, so this step is hypothetical at HEAD (see §5).
  2. The bytes are a vote encoding with sigLen bytes 0xFFxx (65,396–65,535) and a body at least 140+sigLen bytes long (≤ 65,675 bytes total — trivially small).
  3. The length guard at line 694 passes (the input is long enough); line 699 computes 140+sigLen in uint16, wraps, and the copy panics with slice bounds out of range [140:139].
  4. In Go, an unrecovered panic crashes the process. Whether that crashes a node depends entirely on the (currently nonexistent) caller's recover discipline — the gossip validators (net/gossip_validate.go) have no recover(), while the net/msg.go stream handler does (msg.go:71).

4. Proof of concept (red → green)

PoC: hunt-v6/fuzz-toolchain/xe-scratch/core/decodevote_repro_test.go (TestDecodeVoteSigLenOverflow), reproducer input committed as hunt-v6/fuzz-toolchain/crashes/decodevote-siglen-65535.bin (65,675 bytes: version 0x02, rep/blockhash/conflict-account fields, zero prev, timestamp, final byte, sigLen = 0xFFFF, 65,535 0xAB signature bytes — built by the test through production EncodeVote, not hand-assembled).

RED (unpatched, xe-scratch @ 89a542e):

--- FAIL: TestDecodeVoteSigLenOverflow (0.00s)
panic: runtime error: slice bounds out of range [140:139] [recovered, repanicked]
github.com/xeprotocol/xe/core.DecodeVote(...)
    xe-scratch/core/encoding.go:699

The same crash fired during the native fuzz run itself: go test -fuzz=FuzzDecodeVote and go test -race ./core/ both fail on the boundary seed (a 65,535-byte-signature vote, seed#2), input length 0x1008b (65,675), at the same line.

GREEN (one-word fix, /tmp/xe-fixed scratch copy only — the real repo was NOT modified): line 699 changed to copy(sig, data[140:140+int(sigLen)]), matching the guard's arithmetic. The reproducer then passes, including the sweep over the whole wrap window (sigLen 65396, 65400, 65500, 65534, 65535):

ok  github.com/xeprotocol/xe/core  0.012s

The fuzzer was also re-run on the fixed copy (FuzzDecodeVote, 120 s — see FUZZ.md) with zero crashes.

5. Attacker prerequisites

None at HEAD — because there is no live path. This is the bound on the severity, stated plainly:

  • No in-repo caller: grep -rn "DecodeVote" xe/ sdk/ dao/ --include=*.go returns only the definition (encoding.go:668), the fuzz harness, and the reproducer. Votes on the wire are JSON (VoteMsg), votes in Badger are JSON (store/badger_store.go PutVote/GetVote), and votesync (net/votesync.go) moves JSON VoteResponses.
  • No privilege, no crafted peer, no special state is needed if a caller existed — the trigger is a single ~64 KiB byte string.
  • The finding is therefore a latent decoder panic, not an exploit.

6. Independent validation and false-positive assessment

  • Mechanism nailed down two ways: (1) the arithmetic: 140+65535 in uint16 is 139 — verified by reading lines 693–699 and by the panic message itself ([140:139]); (2) the red/green proof (§4): the identical input panics unpatched and passes with the int() fix, and the fix changes nothing else.
  • Disproof attempts that failed: (a) "the guard at line 694 prevents it" — false: the guard uses int, the slice uses uint16; they disagree exactly in the wrap window; (b) "the fuzzer input was malformed" — false: the crashing input is a well-formed encoding produced by production EncodeVote from a valid Vote struct (65,535-byte signature), and EncodeVote → DecodeVote must round-trip by the codec's own contract.
  • Not a false positive: the panic is a measured runtime crash on a deterministic input, reproduced three ways (fuzz seed, race run, standalone reproducer test).
  • Duplicate check (fresh, DB 2,506 entries, refreshed 2026-11-15 V6): full-DB searches return 0 hits for sigLen and uint16, and 2 hits for DecodeVote — XE-0945 ("UnmarshalBlock and DecodeVote silently ignore trailing bytes", different mechanism: trailing bytes are ignored, no panic, no length arithmetic) and XE-8703 ("DecodeVote final byte is non-canonical", different mechanism: the final byte accepts values other than 0/1). The 37 panic hits in the DB are different mechanisms (unguarded [:12] slices on NodePeer/CertificateHash/multisig keys — XE-0096, XE-2634, XE-3392, XE-0623, xe#89). The 36 overflow hits are balance/lease arithmetic overflows, not length-field wraparound. Classification: NOVEL on public data (private reports may exist; uniqueness is not guaranteed).
  • Related latent issue, same file, NOT claimed here: the UnmarshalBlock / MarshalBlockCanonical lease_renew asymmetry (marshal emits type byte 0x0E, unmarshal rejects it) is already filed as XE-2635 / xe#84 — DUPLICATE, correctly not re-reported. The EncodeVote uint16 truncation (§2) is noted as a sibling shape, not a separate finding.

7. Severity justification (Minor, ceiling 650 XE)

Minor, not higher, because the 7-Question Gate caps it at Q1: there is no attacker-reachable trigger at HEAD. A panic in dead code cannot shut down a node, split a chain, or lose funds. What keeps it above informational: (a) the function is exported public API of the consensus codec — it is the obvious decoder any future binary-vote path will call; (b) the trigger is tiny (≤ 65,675 bytes) and deterministic; (c) the same file already has a filed panic class (unguarded slices) where reachability made it matter — this is that class's latent member; (d) the fix is one word with zero behaviour change for valid inputs.

Why not Medium: no live caller, no remote trigger, no state impact, no availability impact at HEAD. If the committee finds a caller this worker missed (e.g. in a downstream consumer of the core package), the honest re-rating is Medium (remote-triggerable process panic via a 64 KiB input) — the draft says so rather than claiming it now.

8. Fix suggestion

In core/encoding.go:699, match the guard's arithmetic:

copy(sig, data[140:140+int(sigLen)])

(One word. Verified green in §4.) Optionally, also reject absurd signature lengths early (real votes carry 64-byte ed25519 signatures) and fix the sibling EncodeVote truncation (encoding.go:659: error instead of silently wrapping when len(v.Signature) > 65535).

9. Caveats (kept in the report)

  1. No live caller at HEAD — the severity rests on future-callers, not on a demonstrated exploit. If the committee's bar requires a live trigger, this closes as informational; that outcome is consistent with this draft.
  2. NOVEL means no matching public finding as of the 2026-11-15 V6 refresh (DB 2,506 entries); private reports may exist.
  3. The reproducer and the fuzz harness live in the scratch copy (hunt-v6/fuzz-toolchain/xe-scratch/core/); the real repo was never modified, and the one-word fix was applied only to the throwaway /tmp/xe-fixed copy for the green proof.
  4. The FuzzDecodeVote 120 s run reported in FUZZ.md ran on the fixed copy (the unpatched copy cannot complete a fuzz run: the seed corpus itself crashes). The crash is the finding; the fixed-copy run is the regression baseline.

10. Reproduction (for the committee)

Local only, scratch copy at 89a542e, no network, no node needed:

export PATH=~/workspace/go/go/bin:~/go/bin:$PATH
export TMPDIR=~/workspace/xe-bounty/.tmp
cd ~/workspace/xe-bounty/hunt-v6/fuzz-toolchain/xe-scratch
go test -run TestDecodeVoteSigLenOverflow -count=1 ./core/
# expect: panic: slice bounds out of range [140:139] at core/encoding.go:699

Raw crashing input (65,675 bytes, same construction as the test): hunt-v6/fuzz-toolchain/crashes/decodevote-siglen-65535.bin. Harness: xe-scratch/core/fuzz_xe_test.go (FuzzDecodeVote); reproducer: xe-scratch/core/decodevote_repro_test.go.


Thread

NoName2323-wq2026-11-14 21:38 UTCgithub

Submitted complete fix in PR #564: https://github.com/xeprotocol/xe/pull/564

  • Replaces uint16 slice arithmetic with integer indexing in
  • Adds regression unit test verifying 64 KiB signature lengths decode without panic
  • All tests pass cleanly.
Joseph Denneteam2026-11-20 19:46 UTCgithub

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-13401 and says what differs; it is read like any other.