Skip to content

Commit

Permalink
Fixed bug #71527 Buffer over-write in finfo_open with malformed magic…
Browse files Browse the repository at this point in the history
… file

The actual fix is applying the upstream patch from
file/file@6713ca4
  • Loading branch information
weltling authored and Tyrael committed Mar 30, 2016
1 parent 43416cf commit 7522335
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ext/fileinfo/libmagic/funcs.c
Expand Up @@ -414,7 +414,7 @@ file_check_mem(struct magic_set *ms, unsigned int level)
size_t len;

if (level >= ms->c.len) {
len = (ms->c.len += 20) * sizeof(*ms->c.li);
len = (ms->c.len += 20 + level) * sizeof(*ms->c.li);
ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ?
emalloc(len) :
erealloc(ms->c.li, len));
Expand Down
9 changes: 3 additions & 6 deletions ext/fileinfo/tests/bug68996.phpt
@@ -1,14 +1,11 @@
--TEST--
Bug #68996 (Invalid free of CG(interned_empty_string))
--SKIPIF--
<?php
if (getenv("USE_ZEND_ALLOC") !== "0") {
print "skip Need Zend MM disabled";
}
?>
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
html_errors=1
--ENV--
USE_ZEND_ALLOC=0
--FILE--
<?php
finfo_open(FILEINFO_MIME_TYPE, "\xfc\x63");
Expand All @@ -19,4 +16,4 @@ finfo_open(FILEINFO_MIME_TYPE, "\xfc\x63");
<br />
<b>Warning</b>: : failed to open stream: No such file or directory in <b>%sbug68996.php</b> on line <b>%d</b><br />
<br />
<b>Warning</b>: finfo_open(): in <b>%sbug68996.php</b> on line <b>%d</b><br />
<b>Warning</b>: finfo_open(): Failed to load magic database at '%s�c'. in <b>%sbug68996.php</b> on line <b>%d</b><br />
1 change: 1 addition & 0 deletions ext/fileinfo/tests/bug71527.magic
@@ -0,0 +1 @@
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
19 changes: 19 additions & 0 deletions ext/fileinfo/tests/bug71527.phpt
@@ -0,0 +1,19 @@
--TEST--
Bug #71527 Buffer over-write in finfo_open with malformed magic file
--SKIPIF--
<?php
if (!class_exists('finfo'))
die('skip no fileinfo extension');
--ENV--
USE_ZEND_ALLOC=0
--FILE--
<?php
$finfo = finfo_open(FILEINFO_NONE, dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug71527.magic");
$info = finfo_file($finfo, __FILE__);
var_dump($info);
?>
--EXPECTF--
Warning: finfo_open(): Failed to load magic database at '%sbug71527.magic'. in %sbug71527.php on line %d

Warning: finfo_file() expects parameter 1 to be resource, boolean given in %sbug71527.php on line %d
bool(false)

0 comments on commit 7522335

Please sign in to comment.