Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ext/zlib/tests/gzseek_seek_oob.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test function gzseek() by seeking out of bounds
--EXTENSIONS--
zlib
--FILE--
<?php
$f = __DIR__."/004.txt.gz";
$h = gzopen($f, 'r');

var_dump(gzseek($h, -100, SEEK_CUR));
var_dump(gzseek($h, 0, SEEK_CUR));
var_dump(gztell($h));

gzclose($h);
?>
--EXPECT--
int(-1)
int(0)
int(0)
9 changes: 7 additions & 2 deletions ext/zlib/zlib_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ static int php_gziop_seek(php_stream *stream, zend_off_t offset, int whence, zen
php_error_docref(NULL, E_WARNING, "SEEK_END is not supported");
return -1;
}
*newoffs = gzseek(self->gz_file, offset, whence);

return (*newoffs < 0) ? -1 : 0;
z_off_t new_offset = gzseek(self->gz_file, offset, whence);
if (new_offset < 0) {
return -1;
}

*newoffs = new_offset;
return 0;
}

static int php_gziop_close(php_stream *stream, int close_handle)
Expand Down
Loading