mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-09-14 09:46:39 +00:00
Merge pull request #99 from ErikBrown2/fix-advert-path-zero-bytes
Fix ADVERT_PATH parsing of embedded zero bytes
This commit is contained in:
@@ -149,7 +149,8 @@ class MessageReader:
|
||||
else:
|
||||
r["path_hash_mode"] = plen >> 6 # 2 upper bytes
|
||||
r["path_len"] = plen & 0x3F
|
||||
r["path"] = dbuf.read().replace(b"\0", b"").hex()
|
||||
path_byte_count = r["path_len"] * (r["path_hash_mode"] + 1)
|
||||
r["path"] = dbuf.read(path_byte_count).hex()
|
||||
|
||||
await self.dispatcher.dispatch(Event(EventType.ADVERT_PATH, r))
|
||||
|
||||
|
||||
@@ -277,4 +277,29 @@ async def test_parse_packet_payload_txt_type_decodes_high_bits():
|
||||
)
|
||||
assert log_data["attempt"] == 1, (
|
||||
f"Expected attempt=1, got {log_data['attempt']}"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_advert_path_preserves_embedded_zero_bytes():
|
||||
"""ADVERT_PATH must preserve valid 0x00 bytes inside path hashes."""
|
||||
dispatcher = _CapturingDispatcher()
|
||||
reader = MessageReader(dispatcher)
|
||||
|
||||
# ADVERT_PATH (0x0e), 2 hops, 3-byte hashes.
|
||||
# path_len byte: hash mode 2 (3 bytes) + 2 hops = 0x82.
|
||||
# The first hash deliberately contains an embedded 0x00 byte.
|
||||
packet = bytearray.fromhex("0e8212003456789a")
|
||||
|
||||
await reader.handle_rx(packet)
|
||||
|
||||
advert_path_events = [
|
||||
e for e in dispatcher.events if e.type == EventType.ADVERT_PATH
|
||||
]
|
||||
|
||||
assert len(advert_path_events) == 1
|
||||
|
||||
payload = advert_path_events[0].payload
|
||||
assert payload["path_hash_mode"] == 2
|
||||
assert payload["path_len"] == 2
|
||||
assert payload["path"] == "12003456789a"
|
||||
|
||||
Reference in New Issue
Block a user