Skip to content

Commit 66d4441

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-20732: Phar::LoadPhar undefined behavior when loading directory
2 parents c35224e + 9686936 commit 66d4441

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ PHP NEWS
3030
. Fixed bug GH-20674 (Fix GH-20674 mb_decode_mimeheader does not handle
3131
separator). (Yuya Hamada)
3232

33+
- Phar:
34+
. Fixed bug GH-20732 (Phar::LoadPhar undefined behavior when reading fails).
35+
(ndossche)
36+
3337
- Sqlite3:
3438
. Fixed bug GH-20699 (SQLite3Result fetchArray return array|false,
3539
null returned). (ndossche, plusminmax)

ext/phar/phar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16191619
const zend_long readsize = sizeof(buffer) - sizeof(token);
16201620
const zend_long tokenlen = sizeof(token) - 1;
16211621
zend_long halt_offset;
1622-
size_t got;
1622+
ssize_t got;
16231623
uint32_t compression = PHAR_FILE_COMPRESSED_NONE;
16241624

16251625
if (error) {
@@ -1637,7 +1637,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16371637
/* Maybe it's better to compile the file instead of just searching, */
16381638
/* but we only want the offset. So we want a .re scanner to find it. */
16391639
while(!php_stream_eof(fp)) {
1640-
if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) < (size_t) tokenlen) {
1640+
if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) < tokenlen) {
16411641
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)")
16421642
}
16431643

ext/phar/tests/gh20732.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20732 (Phar::LoadPhar undefined behavior when loading directory)
3+
--EXTENSIONS--
4+
phar
5+
--FILE--
6+
<?php
7+
try {
8+
@Phar::LoadPhar('.');
9+
} catch (PharException $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
?>
13+
--EXPECTF--
14+
%r(internal corruption of phar "%s" \(truncated entry\)|unable to open phar for reading ".")%r

0 commit comments

Comments
 (0)