From c4b2a5274a48d5d259d323468e86005f55774973 Mon Sep 17 00:00:00 2001 From: Ben Menking Date: Fri, 29 May 2026 13:19:58 -0400 Subject: [PATCH] avoid fatal errors when decoding advert packets --- src/CoreParser.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/CoreParser.php b/src/CoreParser.php index f5fe732..a336f01 100644 --- a/src/CoreParser.php +++ b/src/CoreParser.php @@ -105,14 +105,20 @@ class CoreParser { $m->pub_key = base64_encode(substr($payload, 1, CoreProtocol::PUB_KEY_SIZE)); if( strlen($payload) > CoreProtocol::PUB_KEY_SIZE + 2 ) { - $m->type = ord($payload[33]); - $m->flags = ord($payload[34]); - $m->out_path = substr($payload, 35, CoreProtocol::MAX_PATH_SIZE); - $m->name = substr($payload, 99, 32); - $m->last_advert_time = unpack('V', substr($payload, 203, 4))[1]; - $m->lat = unpack('V', substr($payload, 207, 4))[1]; - $m->lon = unpack('V', substr($payload, 211, 4))[1]; - $m->last_mod = unpack('V', substr($payload, 215, 4))[1]; + try { + $m->type = ord($payload[33]); + $m->flags = ord($payload[34]); + $m->out_path = substr($payload, 35, CoreProtocol::MAX_PATH_SIZE); + $m->name = substr($payload, 99, 32); + $m->last_advert_time = unpack('V', substr($payload, 203, 4))[1]; + $m->lat = unpack('V', substr($payload, 207, 4))[1]; + $m->lon = unpack('V', substr($payload, 211, 4))[1]; + $m->last_mod = unpack('V', substr($payload, 215, 4))[1]; + } + catch(\Throwable $t) { + // hidden problem? packet wasn't long enough so we'll just be missing data i suppose + error_log("Tried to decode Advert but packet too small. Packet size: " . strlen($payload) . " and expected 215.."); + } } return $m;