Skip to content

Commit 428d816

Browse files
committed
Fix bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext)
1 parent 4fc0bce commit 428d816

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ext/phar/phar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,7 @@ int phar_detect_phar_fname_ext(const char *filename, int filename_len, const cha
20172017
}
20182018

20192019
while (pos != filename && (*(pos - 1) == '/' || *(pos - 1) == '\0')) {
2020-
pos = memchr(pos + 1, '.', filename_len - (pos - filename) + 1);
2020+
pos = memchr(pos + 1, '.', filename_len - (pos - filename) - 1);
20212021
if (!pos) {
20222022
return FAILURE;
20232023
}

ext/phar/tests/bug77247.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
PHP bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
try {
8+
var_dump(new Phar('a/.b', 0,'test.phar'));
9+
} catch(UnexpectedValueException $e) {
10+
echo "OK";
11+
}
12+
?>
13+
--EXPECT--
14+
OK

0 commit comments

Comments
 (0)