Fix seenby/path addresses, fix when eom signature is split over the readbuf

This commit is contained in:
Deon George
2021-08-26 22:01:16 +10:00
parent 0834288a28
commit 403dde0d35
2 changed files with 47 additions and 11 deletions

View File

@@ -154,16 +154,10 @@ class Packet extends FTNBase implements \Iterator, \Countable
$buf_ptr = 0;
$message = '';
$readbuf = '';
$last = '';
while ($buf_ptr || (! feof($f) && ($readbuf=fread($f,self::BLOCKSIZE)))) {
// A message header is atleast 0x22 chars long
if (strlen($readbuf) < self::PACKED_MSG_HEADER_LEN) {
$message .= $readbuf;
$buf_ptr = 0;
continue;
} elseif (strlen($message) < self::PACKED_MSG_HEADER_LEN) {
if (strlen($message) < self::PACKED_MSG_HEADER_LEN) {
$addchars = self::PACKED_MSG_HEADER_LEN-strlen($message);
$message .= substr($readbuf,$buf_ptr,$addchars);
$buf_ptr += $addchars;
@@ -175,8 +169,35 @@ class Packet extends FTNBase implements \Iterator, \Countable
}
}
// If we didnt find a packet end, perhaps there are no more
// Take 2 chars from the buffer and check if we have our end packet signature
if ($last && ($buf_ptr == 0)) {
$last .= substr($readbuf,0,2);
if (($end=strpos($last,"\x00\x02\x00",$buf_ptr)) !== FALSE) {
$o->parseMessage(substr($message,0,$end-2),$domain);
$last = '';
$message = '';
$buf_ptr = 1+$end;
// Loop to rebuild our header for the next message
continue;
}
$last = '';
}
if (($end=strpos($readbuf,"\x00\x02\x00",$buf_ptr)) === FALSE) {
// In case our packet break is at the end of the buffer
$last = substr($readbuf,-2);
if ((str_contains($last,"\x00")) && ($fstat['size']-ftell($f) > 2)) {
$message .= substr($readbuf,$buf_ptr);
$buf_ptr = 0;
continue;
}
$last = '';
$end = strpos($readbuf,"\x00\x00\x00",$buf_ptr);
}