Skip to content

Commit 20ab519

Browse files
committed
Fix Endless loop
1 parent 7d49a55 commit 20ab519

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/ChunkedDecoder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ public function handleData($data)
9595
return;
9696
}
9797

98-
$hexValue = strtolower(substr($this->buffer, 0, $positionClrf));
99-
if (dechex(hexdec($hexValue)) !== $hexValue || hexdec($hexValue) > 2147483647) {
98+
$hexValue = strtolower((string)substr($this->buffer, 0, $positionClrf));
99+
if (dechex(hexdec($hexValue)) !== $hexValue) {
100100
$this->handleError(new \Exception($hexValue . ' is not a hexadecimal number or too big'));
101101
return;
102102
}
103103

104104
$this->chunkSize = hexdec($hexValue);
105-
$this->buffer = substr($this->buffer, strlen($hexValue) + 2);
105+
$this->buffer = (string)substr($this->buffer, strlen($hexValue) + 2);
106106
$this->headerCompleted = true;
107107
if ($this->buffer === '') {
108108
return;
109109
}
110110
}
111111

112-
$chunk = substr($this->buffer, 0, $this->chunkSize - $this->transferredSize);
112+
$chunk = (string)substr($this->buffer, 0, $this->chunkSize - $this->transferredSize);
113113
if ($chunk !== '') {
114114
$this->transferredSize += strlen($chunk);
115115
if ($this->transferredSize > $this->chunkSize) {
@@ -118,7 +118,7 @@ public function handleData($data)
118118
}
119119

120120
$this->emit('data', array($chunk));
121-
$this->buffer = substr($this->buffer, strlen($chunk));
121+
$this->buffer = (string)substr($this->buffer, strlen($chunk));
122122
}
123123

124124
if (strpos($this->buffer, static::CRLF) !== false) {
@@ -132,7 +132,7 @@ public function handleData($data)
132132
$this->chunkSize = 0;
133133
$this->headerCompleted = false;
134134
$this->transferredSize = 0;
135-
$this->buffer = substr($this->buffer, 2);
135+
$this->buffer = (string)substr($this->buffer, 2);
136136
}
137137
}
138138
}

0 commit comments

Comments
 (0)