Skip to content

Commit 83f8f24

Browse files
committed
Fix OOB gzseek() causing assertion failure
1 parent 0f5a7d0 commit 83f8f24

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

ext/zlib/tests/gzseek_seek_oob.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ var_dump(gztell($h));
1313

1414
gzclose($h);
1515
?>
16-
--EXPECTF--
16+
--EXPECT--
1717
int(-1)
18-
php: %s: _php_stream_seek: Assertion `stream->position >= 0' failed.
19-
20-
Termsig=6
18+
int(0)
19+
int(0)

ext/zlib/zlib_fopen_wrapper.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ static int php_gziop_seek(php_stream *stream, zend_off_t offset, int whence, zen
9494
php_error_docref(NULL, E_WARNING, "SEEK_END is not supported");
9595
return -1;
9696
}
97-
*newoffs = gzseek(self->gz_file, offset, whence);
9897

99-
return (*newoffs < 0) ? -1 : 0;
98+
off_t new_offset = gzseek(self->gz_file, offset, whence);
99+
if (new_offset < 0) {
100+
return -1;
101+
}
102+
103+
*newoffs = new_offset;
104+
return 0;
100105
}
101106

102107
static int php_gziop_close(php_stream *stream, int close_handle)

0 commit comments

Comments
 (0)