meshcore_py/src/meshcore
Matthew Wolter 865c1b21b4 G1: NEW-B — wrap parsePacketPayload ADVERT branch in try/except
The ADVERT branch in MeshcorePacketParser.parsePacketPayload reads the
flags byte with `pk_buf.read(1)[0]`, which IndexErrors on a short
advert payload (the minimum advert is 32 + 4 + 64 + 1 = 101 bytes
before any optional fields). Pre-F06, the IndexError would escape as a
swallowed task exception. With F06's umbrella now in place it would
log and skip the dispatch, but the proposal §4.1 NEW-B asks for a
narrower local guard so a malformed advert doesn't poison the rest of
the parse path.

The optional `lat/lon/feat1/feat2` reads after the flags byte also
silently produce zeros on short reads (`int.from_bytes(b"", ...)`
returns 0), which would propagate bogus zero coordinates upstream.
Wrapping the whole branch limits the blast radius to a single
malformed advert.

Wrap the entire body of the ADVERT elif (from `pk_buf = io.BytesIO(...)`
through the final `log_data["adv_feat2"]` assignment) in
`try/except (IndexError, ValueError)` and log a debug message with the
exception type, message, and `pkt_payload` length on failure. This
matches the defensive pattern the proposal specifies.

Finding: NEW-B (S3)
File: src/meshcore/meshcore_parser.py
2026-04-11 18:29:41 -07:00
..
commands Use firmware suggested_timeout for login and path discovery sync methods 2026-04-08 21:42:21 -07:00
__init__.py Export binary req type 2025-09-07 12:28:26 -07:00
ble_cx.py Add optional bleak package import handling 2026-02-10 10:30:51 +01:00
connection_manager.py Revert "Refactor command system to be queue based" 2025-09-04 15:08:08 -07:00
events.py add code_string to error event 2026-03-07 21:05:00 -04:00
lpp_json_encoder.py fix lpp values for voltage and current as signed 2026-02-17 08:52:56 -04:00
meshcore.py if possible, add path and rssi to channel messages 2026-03-05 11:50:41 -04:00
meshcore_parser.py G1: NEW-B — wrap parsePacketPayload ADVERT branch in try/except 2026-04-11 18:29:41 -07:00
packets.py implement advert_path 2026-03-07 17:42:41 -04:00
parsing.py Revert "Refactor command system to be queue based" 2025-09-04 15:08:08 -07:00
reader.py G1: NEW-C — add length guard to STATUS_RESPONSE push handler 2026-04-11 18:21:27 -07:00
serial_cx.py Use the frame start once we've found it 2026-03-21 21:08:04 -07:00
tcp_cx.py apply frame header fix to tcp as well 2026-03-22 12:51:01 -04:00