Skip to content

Reject PDUs whose length is shorter than their fixed fields - #75

Merged
stewartadam merged 2 commits into
mainfrom
claude/project-thread-njq8b9-1-parse-short-pdu
Nov 12, 2026
Merged

stewartadam merged 2 commits into
mainfrom
claude/project-thread-njq8b9-1-parse-short-pdu

Conversation

@stewartadam

@stewartadam stewartadam commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

AcnRootLayerProtocol::parse panicked on packets whose PDU length field was shorter than that layer's fixed header. The panic was an out-of-bounds slice in the root layer (CID), the data packet framing layer, and the DMP layer. Because the receiver parses every datagram it gets, any host on the network could crash a receiver with a single packet. E1.31-2016 requires malformed packets to be discarded.

Each layer now checks its length against its own header size before slicing:

Layer Minimum length Error
Root layer 22 (flags/length + vector + CID) PduInvalidLength
Data packet framing layer 77 (all fields before the DMP layer) PduInvalidLength
DMP layer 10 (all fields before the property values) ParseInsufficientData, matching the existing tests for this layer

The sync and discovery layers already had these checks.

Tests

  • New tests/malformed_length_tests.rs has one regression test per crash, plus a sweep that sets every 12-bit length value on each of the three length fields of a valid packet. All four tests panic on main and pass on this branch.
  • cargo test and cargo clippy both pass. Clippy reports no new warnings.

A root layer, data packet framing layer or DMP layer whose length field
was smaller than the fixed fields of that layer caused an out-of-bounds
slice and a panic while parsing. Any host on the network could crash a
receiver with a single malformed datagram.

Each of these layers now returns PduInvalidLength when its length can't
hold its own header, as E1.31 requires malformed packets to be discarded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KzaQVQThQpmqhvLapk99Vs
The existing DMP layer tests expect ParseInsufficientData when the PDU
length is too low, so keep that error type for the new header check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KzaQVQThQpmqhvLapk99Vs
@stewartadam
stewartadam merged commit 75744a8 into main Nov 12, 2026
4 checks passed
@stewartadam
stewartadam deleted the claude/project-thread-njq8b9-1-parse-short-pdu branch November 12, 2026 09:44
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.

2 participants