]> granicus.if.org Git - php/commitdiff
Fixed bug #71527 Buffer over-write in finfo_open with malformed magic file
authorAnatol Belski <ab@php.net>
Sun, 27 Mar 2016 22:45:19 +0000 (00:45 +0200)
committerAnatol Belski <ab@php.net>
Tue, 29 Mar 2016 11:10:39 +0000 (13:10 +0200)
The actual fix is applying the upstream patch from
https://github.com/file/file/commit/6713ca45e7757297381f4b4cdb9cf5e624a9ad36

ext/fileinfo/libmagic/funcs.c
ext/fileinfo/tests/bug71527.magic [new file with mode: 0644]
ext/fileinfo/tests/bug71527.phpt [new file with mode: 0644]

index 011ca42757f386e023cad6d0385062a96218d088..def2f7b31bcbadaafd00e0418ed50c9505309c28 100644 (file)
@@ -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));
diff --git a/ext/fileinfo/tests/bug71527.magic b/ext/fileinfo/tests/bug71527.magic
new file mode 100644 (file)
index 0000000..14d7781
--- /dev/null
@@ -0,0 +1 @@
+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
\ No newline at end of file
diff --git a/ext/fileinfo/tests/bug71527.phpt b/ext/fileinfo/tests/bug71527.phpt
new file mode 100644 (file)
index 0000000..f5b1d86
--- /dev/null
@@ -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)