Skip to content

Refuse to build feature objects larger than u16::MAX bytes#4705

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
TheBlueMatt:2026-05-no-huge-features
Jun 17, 2026
Merged

Refuse to build feature objects larger than u16::MAX bytes#4705
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
TheBlueMatt:2026-05-no-huge-features

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

These aren't serialize-able and clearly bogus.

Reported by Project Loupe

Not gonna bother with backports here this is trivial

@ldk-reviews-bot

ldk-reviews-bot commented Jun 16, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-claude-review-bot

ldk-claude-review-bot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

No issues found.

The PR diff now includes a second change beyond my prior review (the Readable impl in impl_feature_len_prefixed_write!). I reviewed it:

  • lightning/src/ln/features.rs:43-46 — the new manual read (u16 length + read_exact) is correct and symmetric with the write side, which writes a plain u16 length (features.rs:37). The previous Vec::<u8>::read used CollectionLength decoding (ser.rs:585), where 0xffff is an escape prefix followed by a u64 — so a 65535-byte feature would have mis-deserialized. This is a real fix, and it correctly complements the new set_bit cap that now permits features up to exactly 65535 bytes. Allocation is bounded to 64KB, so no DoS concern.
  • lightning-types/src/features.rs:1271 — bounds check confirmed correct in prior review (no off-by-one).

Cross-cutting: still no unit test exercising the new boundary (65534/65535-byte features round-tripping through serialize/deserialize), though the author noted the change is trivial.

@ldk-reviews-bot ldk-reviews-bot requested a review from jkczyz June 16, 2026 16:12
Comment on lines +1271 to +1273
if byte_offset >= u16::MAX as usize {
return Err(());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also change the de-serialization code?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't really seem worth it tbh but certainly could.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be worth it to keep the ser/deser code aligned. Should we also check when parsing with FeatureFlags::from?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure its worth making all the conversion logic fallible for this. Technically maybe we should, but given we won't deserialize them I'm not sure where they'd come from?

@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

These aren't serialize-able and clearly bogus.

Reported by Project Loupe
This shouldn't really matter in practice, but it aligns the
serialization and deserialization logic.

Reported by Project Loupe.
@TheBlueMatt TheBlueMatt force-pushed the 2026-05-no-huge-features branch from 737d519 to 87c8c32 Compare June 17, 2026 14:39
@TheBlueMatt TheBlueMatt requested a review from jkczyz June 17, 2026 14:39
@TheBlueMatt TheBlueMatt merged commit 8a0464c into lightningdevkit:main Jun 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants