Skip to content

Commit

Permalink
Fix bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext)
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Jan 6, 2019
1 parent 4fc0bce commit 428d816
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ int phar_detect_phar_fname_ext(const char *filename, int filename_len, const cha
}

while (pos != filename && (*(pos - 1) == '/' || *(pos - 1) == '\0')) {
pos = memchr(pos + 1, '.', filename_len - (pos - filename) + 1);
pos = memchr(pos + 1, '.', filename_len - (pos - filename) - 1);
if (!pos) {
return FAILURE;
}
Expand Down
14 changes: 14 additions & 0 deletions ext/phar/tests/bug77247.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
PHP bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext)
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--FILE--
<?php
try {
var_dump(new Phar('a/.b', 0,'test.phar'));
} catch(UnexpectedValueException $e) {
echo "OK";
}
?>
--EXPECT--
OK

0 comments on commit 428d816

Please sign in to comment.