Skip to content

Commit 9686936

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-20732: Phar::LoadPhar undefined behavior when loading directory
2 parents 0590a34 + 22aaa20 commit 9686936

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
@@ -29,6 +29,10 @@ PHP NEWS
2929
. Fixed bug GH-20674 (Fix GH-20674 mb_decode_mimeheader does not handle
3030
separator). (Yuya Hamada)
3131

32+
- Phar:
33+
. Fixed bug GH-20732 (Phar::LoadPhar undefined behavior when reading fails).
34+
(ndossche)
35+
3236
- SPL:
3337
. Fixed bug GH-20678 (resource created by GlobIterator crashes with fclose()).
3438
(David Carlier)

ext/phar/phar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16111611
const zend_long readsize = sizeof(buffer) - sizeof(token);
16121612
const zend_long tokenlen = sizeof(token) - 1;
16131613
zend_long halt_offset;
1614-
size_t got;
1614+
ssize_t got;
16151615
uint32_t compression = PHAR_FILE_COMPRESSED_NONE;
16161616

16171617
if (error) {
@@ -1629,7 +1629,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16291629
/* Maybe it's better to compile the file instead of just searching, */
16301630
/* but we only want the offset. So we want a .re scanner to find it. */
16311631
while(!php_stream_eof(fp)) {
1632-
if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) < (size_t) tokenlen) {
1632+
if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) < tokenlen) {
16331633
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)")
16341634
}
16351635

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)