Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
const zend_long readsize = sizeof(buffer) - sizeof(token);
const zend_long tokenlen = sizeof(token) - 1;
zend_long halt_offset;
size_t got;
ssize_t got;
uint32_t compression = PHAR_FILE_COMPRESSED_NONE;

if (error) {
Expand All @@ -1627,7 +1627,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
/* Maybe it's better to compile the file instead of just searching, */
/* but we only want the offset. So we want a .re scanner to find it. */
while(!php_stream_eof(fp)) {
if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) < (size_t) tokenlen) {
if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) < tokenlen) {
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)")
}

Expand Down
15 changes: 15 additions & 0 deletions ext/phar/tests/gh20732.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
GH-20732 (Phar::LoadPhar undefined behavior when loading directory)
--EXTENSIONS--
phar
--FILE--
<?php
try {
Phar::LoadPhar('.');
} catch (PharException $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Notice: Phar::loadPhar(): Read of 8192 bytes failed with errno=21 Is a directory in %s on line %d
internal corruption of phar "/run/media/niels/MoreData/php-8.3" (truncated entry)
Loading