Skip to content

Commit ca46d0a

Browse files
committed
Fix int overflows in phar (bug #73764)
1 parent 2ba3b27 commit ca46d0a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

ext/phar/phar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char
10551055
entry.is_persistent = mydata->is_persistent;
10561056

10571057
for (manifest_index = 0; manifest_index < manifest_count; ++manifest_index) {
1058-
if (buffer + 4 > endbuffer) {
1058+
if (buffer + 24 > endbuffer) {
10591059
MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)")
10601060
}
10611061

@@ -1069,7 +1069,7 @@ static int phar_parse_pharfile(php_stream *fp, char *fname, int fname_len, char
10691069
entry.manifest_pos = manifest_index;
10701070
}
10711071

1072-
if (entry.filename_len + 20 > endbuffer - buffer) {
1072+
if (entry.filename_len > endbuffer - buffer - 20) {
10731073
MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)");
10741074
}
10751075

ext/phar/tests/bug73764.phar

138 Bytes
Binary file not shown.

ext/phar/tests/bug73764.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Phar: PHP bug #73764: Crash while loading hostile phar archive
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
chdir(__DIR__);
8+
try {
9+
$p = Phar::LoadPhar('bug73764.phar', 'alias.phar');
10+
echo "OK\n";
11+
} catch(PharException $e) {
12+
echo $e->getMessage();
13+
}
14+
?>
15+
--EXPECTF--
16+
internal corruption of phar "%sbug73764.phar" (truncated manifest entry)

0 commit comments

Comments
 (0)