{"id":"XE-13401","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"563","source_url":"https://github.com/xeprotocol/xe/issues/563","reporter_id":2381,"title":"DecodeVote panics on a crafted vote encoding: uint16 length wraparound at core/encoding.go:699","area":"consensus","claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:17.232365+00:00","updated_at":"2026-11-20T19:47:48.536017+00:00","source_created_at":"2026-11-14T19:23:02+00:00","told_at":"2026-11-20T19:46:22+00:00","status_changed_at":"2026-11-20T19:46:01.609049+00:00","url":"https://bounty.xe.network/XE-13401","body":"**Severity: Minor** (XE tier ceiling 650 XE). No CVSS vector is asserted:\nthere is no attacker-reachable trigger at HEAD (see §5), so a CVSS\nscore would imply an exploitability the evidence does not support. See\n§7 for the severity reasoning.\n\n**Target:** `github.com/xeprotocol/xe` @\n`89a542ea51d38375299aee54c6c99102e9bfa666` (\"release: testnet-0005 quorum\nwithhold fix\", 2026-11-10). Go 1.25.4.\n\n## 1. Impact (read this first)\n\n`core.DecodeVote` — the exported decoder for the canonical binary vote\nencoding — **panics** (`runtime error: slice bounds out of range\n[140:139]`) on a well-formed vote encoding whose signature is\n65,396–65,535 bytes long. The panic is deterministic, needs no\nmutation luck: a boundary seed (a vote with a 65,535-byte signature,\nbuilt through the production `EncodeVote`) crashes it on first call.\n\nThe honest bound, stated up front: **at HEAD this function has no\nin-repo callers** — votes travel as JSON (`net/messages.go VoteMsg`),\nand `DecodeVote` is called from nowhere in `xe/`, `sdk/`, or `dao/`\n(verified by repo-wide grep, §6). So today this is a latent panic in\nan exported decoder, not a live remote node crash. Its value is as a\nhardening fix: the function is the public decoder for the consensus\nvote format, and any future caller — a binary vote wire path, a\nfuture votesync, out-of-tree tooling — inherits a deterministic panic\non a ~64 KiB input. The fix is one word (§8). The committee may\nreasonably close this as informational; the draft does not inflate\nit beyond Minor.\n\n## 2. Root cause\n\n`core/encoding.go:693` reads the signature length as `uint16`:\n\n```go\nsigLen := binary.BigEndian.Uint16(data[138:140])\nif len(data) < 140+int(sigLen) {   // line 694: INT arithmetic — correct\n    return nil, fmt.Errorf(\"DecodeVote: data truncated: ...\")\n}\n\nsig := make([]byte, sigLen)\ncopy(sig, data[140:140+sigLen])   // line 699: UINT16 arithmetic — wraps\n```\n\nLine 694 guards with `int` arithmetic, but line 699 slices with\n`uint16` arithmetic. In Go, `140+sigLen` with `sigLen uint16` is\ncomputed in `uint16`: for `sigLen` in (65395, 65535], `140+sigLen`\nexceeds 65535 and wraps modulo 65536. For `sigLen = 65535`:\n`140+65535 = 65675 → wraps to 139`, so the slice becomes\n`data[140:139]` and panics. The guard passes because the input really\nis long enough (`len(data) = 65675 = 140+65535`); the guard and the\nslice disagree about the arithmetic, and the slice is the one that\nis wrong.\n\nThe same file's sibling encoder has the matching latent shape:\n`EncodeVote` (encoding.go:659) does `sigLen := uint16(len(v.Signature))`,\nsilently truncating any signature longer than 65,535 bytes before\nwriting the length — harmless in practice (real signatures are 64\nbytes) but the same class of unchecked narrowing.\n\n## 3. Scenario (how it happens)\n\n1. A caller passes attacker-influenced bytes to `DecodeVote` — today\n   no such caller exists in-repo, so this step is hypothetical at\n   HEAD (see §5).\n2. The bytes are a vote encoding with `sigLen` bytes `0xFFxx`\n   (65,396–65,535) and a body at least `140+sigLen` bytes long\n   (≤ 65,675 bytes total — trivially small).\n3. The length guard at line 694 passes (the input is long enough);\n   line 699 computes `140+sigLen` in `uint16`, wraps, and the\n   `copy` panics with `slice bounds out of range [140:139]`.\n4. In Go, an unrecovered panic crashes the process. Whether that\n   crashes a node depends entirely on the (currently nonexistent)\n   caller's recover discipline — the gossip validators\n   (`net/gossip_validate.go`) have **no** `recover()`, while the\n   `net/msg.go` stream handler does (msg.go:71).\n\n## 4. Proof of concept (red → green)\n\nPoC: `hunt-v6/fuzz-toolchain/xe-scratch/core/decodevote_repro_test.go`\n(`TestDecodeVoteSigLenOverflow`), reproducer input committed as\n`hunt-v6/fuzz-toolchain/crashes/decodevote-siglen-65535.bin`\n(65,675 bytes: version `0x02`, rep/blockhash/conflict-account fields,\nzero `prev`, timestamp, final byte, `sigLen = 0xFFFF`, 65,535\n`0xAB` signature bytes — built by the test through production\n`EncodeVote`, not hand-assembled).\n\nRED (unpatched, xe-scratch @ 89a542e):\n\n```\n--- FAIL: TestDecodeVoteSigLenOverflow (0.00s)\npanic: runtime error: slice bounds out of range [140:139] [recovered, repanicked]\ngithub.com/xeprotocol/xe/core.DecodeVote(...)\n    xe-scratch/core/encoding.go:699\n```\n\nThe same crash fired during the native fuzz run itself:\n`go test -fuzz=FuzzDecodeVote` and `go test -race ./core/` both\nfail on the boundary seed (a 65,535-byte-signature vote, seed#2),\ninput length `0x1008b` (65,675), at the same line.\n\nGREEN (one-word fix, `/tmp/xe-fixed` scratch copy only — the real\nrepo was NOT modified): line 699 changed to\n`copy(sig, data[140:140+int(sigLen)])`, matching the guard's\narithmetic. The reproducer then passes, including the sweep over\nthe whole wrap window (sigLen 65396, 65400, 65500, 65534, 65535):\n\n```\nok  github.com/xeprotocol/xe/core  0.012s\n```\n\nThe fuzzer was also re-run on the fixed copy\n(`FuzzDecodeVote`, 120 s — see FUZZ.md) with zero crashes.\n\n## 5. Attacker prerequisites\n\n**None at HEAD — because there is no live path.** This is the bound\non the severity, stated plainly:\n\n- No in-repo caller: `grep -rn \"DecodeVote\" xe/ sdk/ dao/ --include=*.go`\n  returns only the definition (encoding.go:668), the fuzz harness,\n  and the reproducer. Votes on the wire are JSON (`VoteMsg`), votes\n  in Badger are JSON (`store/badger_store.go` `PutVote`/`GetVote`),\n  and votesync (`net/votesync.go`) moves JSON `VoteResponse`s.\n- No privilege, no crafted peer, no special state is needed *if* a\n  caller existed — the trigger is a single ~64 KiB byte string.\n- The finding is therefore a latent decoder panic, not an exploit.\n\n## 6. Independent validation and false-positive assessment\n\n- **Mechanism nailed down two ways:** (1) the arithmetic: `140+65535`\n  in `uint16` is 139 — verified by reading lines 693–699 and by the\n  panic message itself (`[140:139]`); (2) the red/green proof (§4):\n  the identical input panics unpatched and passes with the `int()`\n  fix, and the fix changes nothing else.\n- **Disproof attempts that failed:** (a) \"the guard at line 694\n  prevents it\" — false: the guard uses `int`, the slice uses\n  `uint16`; they disagree exactly in the wrap window; (b) \"the\n  fuzzer input was malformed\" — false: the crashing input is a\n  well-formed encoding produced by production `EncodeVote` from a\n  valid `Vote` struct (65,535-byte signature), and `EncodeVote` →\n  `DecodeVote` must round-trip by the codec's own contract.\n- **Not a false positive:** the panic is a measured runtime crash on\n  a deterministic input, reproduced three ways (fuzz seed, race run,\n  standalone reproducer test).\n- **Duplicate check (fresh, DB 2,506 entries, refreshed 2026-11-15\n  V6):** full-DB searches return 0 hits for `sigLen` and `uint16`,\n  and 2 hits for `DecodeVote` — XE-0945 (\"UnmarshalBlock and DecodeVote\n  silently ignore trailing bytes\", different mechanism: trailing\n  bytes are ignored, no panic, no length arithmetic) and XE-8703\n  (\"DecodeVote final byte is non-canonical\", different mechanism:\n  the `final` byte accepts values other than 0/1). The 37 `panic`\n  hits in the DB are different mechanisms (unguarded `[:12]`\n  slices on NodePeer/CertificateHash/multisig keys — XE-0096,\n  XE-2634, XE-3392, XE-0623, xe#89). The 36 `overflow` hits are\n  balance/lease arithmetic overflows, not length-field wraparound.\n  Classification: **NOVEL on public data** (private reports may\n  exist; uniqueness is not guaranteed).\n- **Related latent issue, same file, NOT claimed here:** the\n  `UnmarshalBlock` / `MarshalBlockCanonical` lease_renew asymmetry\n  (marshal emits type byte `0x0E`, unmarshal rejects it) is already\n  filed as XE-2635 / xe#84 — DUPLICATE, correctly not re-reported.\n  The `EncodeVote` uint16 truncation (§2) is noted as a sibling\n  shape, not a separate finding.\n\n## 7. Severity justification (Minor, ceiling 650 XE)\n\nMinor, not higher, because the 7-Question Gate caps it at Q1: there\nis no attacker-reachable trigger at HEAD. A panic in dead code\ncannot shut down a node, split a chain, or lose funds. What keeps it\nabove informational: (a) the function is exported public API of the\nconsensus codec — it is the obvious decoder any future binary-vote\npath will call; (b) the trigger is tiny (≤ 65,675 bytes) and\ndeterministic; (c) the same file already has a filed panic class\n(unguarded slices) where reachability made it matter — this is that\nclass's latent member; (d) the fix is one word with zero behaviour\nchange for valid inputs.\n\nWhy not Medium: no live caller, no remote trigger, no state impact,\nno availability impact at HEAD. If the committee finds a caller this\nworker missed (e.g. in a downstream consumer of the core package),\nthe honest re-rating is Medium (remote-triggerable process panic via\na 64 KiB input) — the draft says so rather than claiming it now.\n\n## 8. Fix suggestion\n\nIn `core/encoding.go:699`, match the guard's arithmetic:\n\n```go\ncopy(sig, data[140:140+int(sigLen)])\n```\n\n(One word. Verified green in §4.) Optionally, also reject absurd\nsignature lengths early (real votes carry 64-byte ed25519\nsignatures) and fix the sibling `EncodeVote` truncation\n(encoding.go:659: error instead of silently wrapping when\n`len(v.Signature) > 65535`).\n\n## 9. Caveats (kept in the report)\n\n1. No live caller at HEAD — the severity rests on future-callers,\n   not on a demonstrated exploit. If the committee's bar requires a\n   live trigger, this closes as informational; that outcome is\n   consistent with this draft.\n2. NOVEL means no matching *public* finding as of the 2026-11-15 V6\n   refresh (DB 2,506 entries); private reports may exist.\n3. The reproducer and the fuzz harness live in the scratch copy\n   (`hunt-v6/fuzz-toolchain/xe-scratch/core/`); the real repo was\n   never modified, and the one-word fix was applied only to the\n   throwaway `/tmp/xe-fixed` copy for the green proof.\n4. The `FuzzDecodeVote` 120 s run reported in FUZZ.md ran on the\n   fixed copy (the unpatched copy cannot complete a fuzz run: the\n   seed corpus itself crashes). The crash is the finding; the\n   fixed-copy run is the regression baseline.\n\n## 10. Reproduction (for the committee)\n\nLocal only, scratch copy at `89a542e`, no network, no node needed:\n\n```bash\nexport PATH=~/workspace/go/go/bin:~/go/bin:$PATH\nexport TMPDIR=~/workspace/xe-bounty/.tmp\ncd ~/workspace/xe-bounty/hunt-v6/fuzz-toolchain/xe-scratch\ngo test -run TestDecodeVoteSigLenOverflow -count=1 ./core/\n# expect: panic: slice bounds out of range [140:139] at core/encoding.go:699\n```\n\nRaw crashing input (65,675 bytes, same construction as the test):\n`hunt-v6/fuzz-toolchain/crashes/decodevote-siglen-65535.bin`.\nHarness: `xe-scratch/core/fuzz_xe_test.go` (`FuzzDecodeVote`);\nreproducer: `xe-scratch/core/decodevote_repro_test.go`.\n\n---","patch_refs":[{"id":582,"repo":"xeprotocol/xe","kind":"pr","ref":"564","title":"core: prevent slice bounds out of range panic in DecodeVote (fixes #563)","url":"https://github.com/xeprotocol/xe/pull/564","note":"","state":"open","author":"NoName2323-wq","added_by":"desk","created_at":"2026-11-14T21:38:55.420532+00:00"}],"thread":[{"id":3163,"source":"github","source_ref":"6884590780","author":"NoName2323-wq","team":false,"body":"Submitted complete fix in PR #564: https://github.com/xeprotocol/xe/pull/564\n\n- Replaces uint16 slice arithmetic with integer indexing in \n- Adds regression unit test  verifying 64 KiB signature lengths decode without panic\n- All tests pass cleanly.","created_at":"2026-11-14T21:38:32+00:00"},{"id":15462,"source":"github","source_ref":"7049041640","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-13401 and says what differs; it is read like any other.","created_at":"2026-11-20T19:46:22+00:00"}]}