← Back to Pull requests

[v0.20.x-branch] Backport #10249: enforce strict TLV length checks #11134

Closed
unknown closed this pull request without merging on Aug 28, 2026 16:13 UTC
View on GitHub
unknown unknown commented on Aug 28, 2026 15:02 UTC
Author

Backport of #10249 (multi: enforce strict TLV length checks) to
v0.20.x-branch.

Why

v0.20.x is missing the strict length validation in the fixed-size TLV
decoders. The tlv stream delegates that check to each decoder:

// We know of this record type, proceed to decode the value.
// This method asserts that length bytes are read in the
// process, and returns an error if the number of bytes is not
// exactly length.
case ok:
        err := rec.decoder(r, rec.value, &s.buf, length)

feeDecoder ignores the l argument, so an inbound-fee record that declares a
length larger than the bytes actually present is silently accepted. It only
consumes 8 bytes, the stream then hits a clean EOF, and decoding succeeds with
ExtraOpaqueData retaining the bogus length. Re-encoding rebuilds the record
canonically, so the message does not round-trip.

This is latent on v0.20.x today: the old ChannelUpdate1.Encode wrote the
merged extra data back into the message, so the round-trip fuzz assertion
compared the encoder's output against itself and never observed the mismatch.

It stops being latent under #11130, which backports #11090. That PR makes the
extra-data canonicalization non-mutating, which removes the rewrite that was
hiding the discrepancy, and five fuzz seeds start failing unit-race and
unit-cover:

--- FAIL: FuzzFailAmountBelowMinimum/4662b612b4d7be63
--- FAIL: FuzzFailAmountBelowMinimum/9fd80ba0c3e2ab94
--- FAIL: FuzzFailIncorrectCltvExpiry/de22154e6461560a
--- FAIL: FuzzFailExpiryTooSoon/30069949c12a8569
--- FAIL: FuzzFailExpiryTooSoon/3325a74843c4d3d6

With this fix the malformed record is rejected at decode, so the harness skips
those inputs, which is exactly how master behaves.

Notes

The upstream release-notes commit targets release-notes-0.21.0.md and
conflicts here, so it is replaced with an equivalent entry in
release-notes-0.20.4.md.
tlv/primitive.go is included for fidelity with upstream, but tlv is a
separate module and go.mod pins lnd/tlv v1.3.2 with no replace, so that
hunk has no effect on the build until tlv is released and bumped. The
effective changes here are in lnwire/ and routing/route/.

Testing

Verified with the lightninglabs/lnd-fuzz corpus rsync'd in, both standalone
and with the #11130 stack rebased on top: builds clean, and -race passes for
lnwire, netann, peer, routing/route, plus the queue and tlv
submodules.

Diff: 309 lines (+231 / -78) across 3 files Reviewer: gijswijs Review duration: 71m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 309 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.343
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11134"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 40.2% (MEDIUM) · Higher = larger blast radius
40.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.9% · Safe to merge
15.9%