just_read = BZ2_bzread(self->bz_file, buf, to_read);
if (just_read < 1) {
- stream->eof = 0 == just_read;
+ /* it is not safe to keep reading after an error, see #72613 */
+ stream->eof = 1;
+ if (just_read < 0) {
+ return -1;
+ }
break;
}
--- /dev/null
+--TEST--
+Bug #72613 (Inadequate error handling in bzread())
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php
+$fp = bzopen(__DIR__.'/72613.bz2', 'r');
+if ($fp === FALSE) {
+ exit("ERROR: bzopen()");
+}
+$data = "";
+while (!feof($fp)) {
+ $res = bzread($fp);
+ if ($res === FALSE) {
+ exit("ERROR: bzread()");
+ }
+ $data .= $res;
+}
+bzclose($fp);
+?>
+DONE
+--EXPECT--
+DONE
\ No newline at end of file