Fix processing packets when we loop without reading

This commit is contained in:
Deon George
2022-11-15 22:01:05 +11:00
parent 3ffb1c1fd6
commit 4e66990826
3 changed files with 6 additions and 5 deletions

View File

@@ -175,7 +175,8 @@ class Packet extends FTNBase implements \Iterator, \Countable
$last = '';
while ($buf_ptr || (! feof($f) && ($readbuf=fread($f,self::BLOCKSIZE)))) {
$read_ptr += strlen($readbuf);
if (! $buf_ptr)
$read_ptr += strlen($readbuf); // Could use ftell()
if (strlen($message) < self::PACKED_MSG_HEADER_LEN) {
$addchars = self::PACKED_MSG_HEADER_LEN-strlen($message);
@@ -207,7 +208,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
}
if (($end=strpos($readbuf,"\x00\x02\x00",$buf_ptr)) === FALSE) {
// In case our packet break is at the end of the buffer
// Just in case our packet break is at the end of the buffer
$last = substr($readbuf,-2);
if ((str_contains($last,"\x00")) && ($size-$read_ptr > 2)) {