From 1ebb937d467c229a764c971718f93f2ec6b663d9 Mon Sep 17 00:00:00 2001 From: f321x Date: Thu, 11 Dec 2025 15:40:23 +0100 Subject: [PATCH] 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. https://github.com/lightning/bolts/blob/0cf21511a781c295b9374aeaef37cf9c4d193502/07-routing-gossip.md?plain=1#L674 # Conflicts: # electrum/lnpeer.py --- electrum/lnpeer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 98e3a292d..55a591c46 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -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)]