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

Merge rust-bitcoin/rust-bitcoin#7168: units: add `visit_units` in optional serde visitors

Public commit record

What the developer wrote

Authored by Andrew Poelstra

100/100 · Strong
Merge rust-bitcoin/rust-bitcoin#7168: units: add `visit_units` in optional serde visitors

26946ac108c196aaddf040e5d61b5aa6fff9e12d units: test optional serde fields through flatten (satsfy (Renato Britto))
8eda9b9672b4aea9fa1d84f00a58a9b538dab38d units: add visit_unit in optional serde visitors (satsfy (Renato Britto))

Pull request description:

Supersedes https://github.com/rust-bitcoin/rust-bitcoin/pull/1472

So deserializing an `Option<Amount>`, `Option<SignedAmount>` or `Option<FeeRate>` through one of our `opt` serde modules failed when the field was inside a `#[serde(flatten)]` struct and the value read was `null` (as often happen in optional fields). This is because `flatten` put a JSON `null` as a serde unit in the buffer, making serde calls `visit_unit()`, which `opt` visitors did not implement, producing an error. Outside `flatten` the same field works because the format calls `visit_none` directly.

This PR the `visit_unit` fns. The test is similar to what #1472 has, which first presented the problem in 2022.


ACKs for top commit:
tcharding:
ACK 26946ac108c196aaddf040e5d61b5aa6fff9e12d
apoelstra:
ACK 26946ac108c196aaddf040e5d61b5aa6fff9e12d; successfully ran local tests


Tree-SHA512: 57a1777a7ab97237f3d9ca90707b5e892d724a080dc363e863ff790293952cc47e528b188da60132a20e7a118ae26b3ec7c3ae94304d390c13a777503153bcc7
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a bug in how optional Bitcoin amount and fee-rate values are read from JSON when those fields are inside a flattened struct and the value is null. Previously, the code would error out because it did not handle a special serde 'unit' representation that serde uses during flattening. The fix adds handlers that treat that unit as None, and adds a test to prevent regression. It is a correctness/robustness fix rather than a typical security vulnerability, but it could cause unexpected deserialization failures in applications relying on these types.

Recommended action

Review downstream code that deserializes Option<Amount>, Option<SignedAmount>, or Option<FeeRate> inside flattened structs; ensure the fix is included in the next release. No immediate security mitigation is required, but consider this a reliability fix that may affect API consumers parsing JSON with optional flattened fields.

Security signals we found

01

Deserialization failure in optional numeric types under serde flatten

02

Missing serde visitor method (visit_unit) causing runtime errors

03

Regression test added for null handling in flattened structs

Risk score

Why this scored 36/100

Our methodology →
Potential impact 8/30
Exploitability 5/25
Stealth signal 4/15
Affected reach 7/15
Confidence 8/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.