Skip to content

Commit

Permalink
Partial fix for bug #72613 - do not allow reading past error read
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Jul 19, 2016
1 parent e4d5587 commit 5faa15c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ext/bz2/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ static size_t php_bz2iop_read(php_stream *stream, char *buf, size_t count)
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;
}

Expand Down
Binary file added ext/bz2/tests/72613.bz2
Binary file not shown.
23 changes: 23 additions & 0 deletions ext/bz2/tests/bug72613.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--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

0 comments on commit 5faa15c

Please sign in to comment.