1
0

lnpeer: decode_short_ids: check length of short ids

- if `encoded_short_ids` does not decode into a whole number of `short_channel_id`:
  - MAY send a `warning`.
  - MAY close the connection.
0cf21511a7/07-routing-gossip.md (L674)

# Conflicts:
#	electrum/lnpeer.py
This commit is contained in:
f321x
2025-12-11 15:40:23 +01:00
parent 380d7edea2
commit 1ebb937d46

View File

@@ -787,7 +787,9 @@ class Peer(Logger, EventListener):
@staticmethod
def decode_short_ids(encoded):
if encoded[0] != 0:
if len(encoded) < 1 or (len(encoded) - 1) % 8 != 0:
raise Exception(f'decode_short_ids: invalid size: {len(encoded)=}')
elif encoded[0] != 0:
raise Exception(f'decode_short_ids: unexpected first byte: {encoded[0]}')
decoded = encoded[1:]
ids = [decoded[i:i+8] for i in range(0, len(decoded), 8)]