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

This commit is contained in:
Deon George 2023-12-09 13:56:45 +11:00
parent 5a74386f5a
commit 8fc0336314

View File

@ -267,10 +267,8 @@ class Packet extends FTNBase implements \Iterator, \Countable
$message .= substr($readbuf,$buf_ptr,$addchars); $message .= substr($readbuf,$buf_ptr,$addchars);
$buf_ptr += $addchars; $buf_ptr += $addchars;
// If our buffer wasnt big enough... // If our buffer wasnt big enough, and thus $addchars didnt have enough chars to add.
// @todo can this be true?
if ($buf_ptr >= strlen($readbuf)) { if ($buf_ptr >= strlen($readbuf)) {
throw new \Exception('We found a situation that this is true');
$buf_ptr = 0; $buf_ptr = 0;
continue; continue;
} }
@ -302,7 +300,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
$last = substr($readbuf,-2); $last = substr($readbuf,-2);
// We have an EOM or EOP marker here, so loop around to get the next read // 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); $message .= substr($readbuf,$buf_ptr);
$buf_ptr = 0; $buf_ptr = 0;