Skip to content

Check lengths before reading short or unexpected frames - #120

Merged
fdlamotte merged 1 commit into
meshcore-dev:mainfrom
hamsolodev:reader-frame-length-checks
Nov 22, 2026
Merged

fdlamotte merged 1 commit into
meshcore-dev:mainfrom
hamsolodev:reader-frame-length-checks

Conversation

@hamsolodev

Copy link
Copy Markdown
Contributor

What was wrong (#119, A1, A3 and A6): a few frames raised in the reader, or were read wrongly, when cut short or carrying a value it didn't expect.

  • RX_LOG_DATA: a transport-route packet of 5 bytes or fewer ended before its path byte, raised IndexError, and no event was dispatched.
  • CUSTOM_VARS: a pair without : (gps) or a trailing comma (gps:1,) raised IndexError, so get_custom_vars waited out its timeout.
  • PATH_DISCOVERY_RESPONSE with a path length of 0xFF read 63 four-byte hops, then raised.
  • MSG_SENT cut to 5 bytes was dispatched with a 3-byte expected_ack and a suggested_timeout of 0.

What changed

  • parsePacketPayload gives a packet cut before its path byte, or inside its path, the same sentinel fields as the existing too-short case, so the RX_LOG_DATA event still goes out.
  • CUSTOM_VARS splits each pair with partition(":") and skips pairs without one. A value containing : now keeps all of it.
  • PATH_DISCOVERY_RESPONSE reads both paths with a small helper: 0xFF reads as no path (-1, as CONTACT's out_path_len does), and a path cut short raises instead of being read short.
  • MSG_SENT shorter than 10 bytes dispatches ERROR with reason: invalid_frame_length, as the STATS and TUNING_PARAMS length checks already do.

Verified with new unit tests in tests/unit/test_reader_frame_lengths.py. The ones for these faults fail on current main. The whole suite passes on 3.11 and 3.14.

Part of #119.

- RX_LOG_DATA: a packet cut before its path byte, or inside its path, gets
  the same sentinel fields as a too-short payload instead of raising.
- CUSTOM_VARS: a pair without ':' (or after a trailing ',') is skipped.
- PATH_DISCOVERY_RESPONSE: a path length of 0xFF reads as no path, and a
  path cut short raises instead of being read short.
- MSG_SENT shorter than 10 bytes is reported as invalid_frame_length
  instead of dispatched with a 3-byte ack and a timeout of 0.

Part of meshcore-dev#119 (A1, A3, A6).
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