From 8fc0336314fcd32be69c25da5e60ed0d662bed94 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 9 Dec 2023 13:56:45 +1100 Subject: [PATCH] Fix for bugs implemented in #e56eca, where the message was including the 3 NULLs at the end and our header is near the end of a buffer read --- app/Classes/FTN/Packet.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 68fc85e..be9f7b3 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -267,10 +267,8 @@ class Packet extends FTNBase implements \Iterator, \Countable $message .= substr($readbuf,$buf_ptr,$addchars); $buf_ptr += $addchars; - // If our buffer wasnt big enough... - // @todo can this be true? + // If our buffer wasnt big enough, and thus $addchars didnt have enough chars to add. if ($buf_ptr >= strlen($readbuf)) { - throw new \Exception('We found a situation that this is true'); $buf_ptr = 0; continue; } @@ -302,7 +300,7 @@ class Packet extends FTNBase implements \Iterator, \Countable $last = substr($readbuf,-2); // We have an EOM or EOP marker here, so loop around to get the next read - if (str_contains($last,"\x00")) { + if (str_contains($last,"\x00") && ($size < $read_ptr)) { $message .= substr($readbuf,$buf_ptr); $buf_ptr = 0;