Skip to content

Commit c666d6b

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix assertion failure when fseeking a phar file out of bounds
2 parents 7809d51 + 3a2868f commit c666d6b

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PHP NEWS
2222
. Fixed bug GH-20442 (Phar does not respect case-insensitiveness of
2323
__halt_compiler() when reading stub). (ndossche, TimWolla)
2424
. Fix broken return value of fflush() for phar file entries. (ndossche)
25+
. Fix assertion failure when fseeking a phar file out of bounds. (ndossche)
2526

2627
- PHPDBG:
2728
. Fixed ZPP type violation in phpdbg_get_executable() and phpdbg_end_oplog().

ext/phar/stream.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,9 @@ static int phar_stream_seek(php_stream *stream, zend_off_t offset, int whence, z
424424

425425
zend_off_t temp_signed = (zend_off_t) temp;
426426
if (temp_signed > data->zero + (zend_off_t) entry->uncompressed_filesize) {
427-
*newoffset = -1; /* FIXME: this will invalidate the ZEND_ASSERT(stream->position >= 0); assertion in streams.c */
428427
return -1;
429428
}
430429
if (temp_signed < data->zero) {
431-
*newoffset = -1; /* FIXME: this will invalidate the ZEND_ASSERT(stream->position >= 0); assertion in streams.c */
432430
return -1;
433431
}
434432
res = php_stream_seek(data->fp, temp_signed, SEEK_SET);

ext/phar/tests/022.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,28 @@ int(1)
8080
fseek($fp, -1, SEEK_END)int(0)
8181
int(6)
8282
fseek($fp, -8, SEEK_END)int(-1)
83-
bool(false)
83+
int(6)
8484
fseek($fp, -7, SEEK_END)int(0)
8585
int(0)
8686
fseek($fp, 0, SEEK_END)int(0)
8787
int(7)
8888
fseek($fp, 1, SEEK_END)int(-1)
89-
bool(false)
89+
int(7)
9090
fseek($fp, -8, SEEK_END)int(-1)
91-
bool(false)
91+
int(7)
9292
fseek($fp, 6)int(0)
9393
int(6)
9494
fseek($fp, 8)int(-1)
95-
bool(false)
95+
int(6)
9696
fseek($fp, -1)int(-1)
97-
bool(false)
97+
int(6)
9898
next
9999
int(4)
100100
fseek($fp, -5, SEEK_CUR)int(-1)
101-
bool(false)
101+
int(4)
102102
int(4)
103103
fseek($fp, 5, SEEK_CUR)int(-1)
104-
bool(false)
104+
int(4)
105105
int(4)
106106
fseek($fp, -4, SEEK_CUR)int(0)
107107
int(0)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Assertion failure when fseeking outside of bounds of phar file
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.require_hash=0
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . '/files/phar_oo_test.inc';
10+
$phar = new Phar($fname);
11+
$phar->setInfoClass('SplFileObject');
12+
$f = $phar['a.php'];
13+
var_dump($f->fseek(1, SEEK_SET));
14+
var_dump($f->fseek(999999, SEEK_SET));
15+
var_dump($f->fseek(999999, SEEK_CUR));
16+
var_dump($f->ftell());
17+
var_dump($f->fseek(1, SEEK_CUR));
18+
var_dump($f->fread(3));
19+
?>
20+
--EXPECT--
21+
int(0)
22+
int(-1)
23+
int(-1)
24+
int(1)
25+
int(0)
26+
string(3) "php"

0 commit comments

Comments
 (0)