Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions ext/phar/tests/gh20732.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--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--
%r(internal corruption of phar "%s" \(truncated entry\)|unable to open phar for reading ".")%r
Loading