AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 34 Bitcoin

consensus_encoding: Introduce decode_from_slice_unbounded

Public commit record

What the developer wrote

Authored by Mitchell Bagot

63/100 · Adequate
consensus_encoding: Introduce decode_from_slice_unbounded

The old consensus code deserialize function returned an error when
decoding failed to consume all bytes in the input slice. The new
nearest-equivalent function, decode_from_slice, does not error on
unconsumed bytes.

Introduce decode_from_slice_unbounded which errors on unconsumed bytes.
Adjust decode_from_slice to error on unconsumed bytes.
Introduce DecodeError type to specify decoder vs unconsumed bytes
errors for decode_from_slice.
✓ Specific, descriptive subject✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit changes how a Bitcoin library decodes byte slices. Previously, a function called decode_from_slice silently accepted extra bytes after a valid object. Now it rejects leftover bytes, and a new function decode_from_slice_unbounded is provided for cases where callers intentionally want to read only part of the input. This is a defensive correctness fix that prevents accidental acceptance of malformed or padded data, but it also changes the public API behavior and error types, which could break downstream code.

Recommended action

Review downstream callers of decode_from_slice to ensure they do not depend on the previous silent acceptance of trailing bytes; update error handling to match the new DecodeError type. Prefer decode_from_slice_unbounded only when intentionally parsing a prefix of a larger buffer. Consider whether this API change warrants a version bump and changelog note because it is a breaking change.

Security signals we found

01

Strict input validation: decode_from_slice now rejects unconsumed trailing bytes, preventing malleability or parsing ambiguity

02

API behavior change: existing callers relying on silent acceptance of extra bytes will now receive errors

03

Error-type change: return type of decode_from_slice changed from Decoder::Error to DecodeError<Decoder::Error>, a breaking public API change

04

New unconsumed-byte error variant improves diagnostics and explicit handling

05

No memory-safety bug evident; change is a semantic hardening of deserialization

Risk score

Why this scored 34/100

Our methodology →
Potential impact 8/30
Exploitability 5/25
Stealth signal 4/15
Affected reach 6/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.