summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2015-01-04 14:23:56 +0100
committerAnatol Belski <ab@php.net>2015-01-04 14:23:56 +0100
commit28e44f9d44501ca18318d31158155313e9226c1a (patch)
treefcc19ed05c7f03b0f93102378a25fd38f191a221
parentc06f66563adaba30f5577add7a4a50bbe24c29e6 (diff)
parentd3f171117c6913e849df004a927dd4915c64124c (diff)
downloadphp-git-28e44f9d44501ca18318d31158155313e9226c1a.tar.gz
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: updated NEWS Fixed bug #68735 fileinfo out-of-bounds memory access
-rw-r--r--ext/fileinfo/libmagic/softmagic.c7
-rw-r--r--ext/fileinfo/tests/bug68735.jpgbin0 -> 24 bytes
-rw-r--r--ext/fileinfo/tests/bug68735.phpt16
3 files changed, 21 insertions, 2 deletions
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
index e000dff92e..1ef31f0f85 100644
--- a/ext/fileinfo/libmagic/softmagic.c
+++ b/ext/fileinfo/libmagic/softmagic.c
@@ -918,14 +918,17 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
size_t sz = file_pstring_length_size(m);
char *ptr1 = p->s, *ptr2 = ptr1 + sz;
size_t len = file_pstring_get_length(m, ptr1);
- if (len >= sizeof(p->s)) {
+ sz = sizeof(p->s) - sz; /* maximum length of string */
+ if (len >= sz) {
/*
* The size of the pascal string length (sz)
* is 1, 2, or 4. We need at least 1 byte for NUL
* termination, but we've already truncated the
* string by p->s, so we need to deduct sz.
+ * Because we can use one of the bytes of the length
+ * after we shifted as NUL termination.
*/
- len = sizeof(p->s) - sz;
+ len = sz;
}
while (len--)
*ptr1++ = *ptr2++;
diff --git a/ext/fileinfo/tests/bug68735.jpg b/ext/fileinfo/tests/bug68735.jpg
new file mode 100644
index 0000000000..633bdb93ed
--- /dev/null
+++ b/ext/fileinfo/tests/bug68735.jpg
Binary files differ
diff --git a/ext/fileinfo/tests/bug68735.phpt b/ext/fileinfo/tests/bug68735.phpt
new file mode 100644
index 0000000000..f86109cb8f
--- /dev/null
+++ b/ext/fileinfo/tests/bug68735.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug #68735 fileinfo out-of-bounds memory access
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--FILE--
+<?php
+ $test_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug68735.jpg";
+ $f = new finfo;
+
+ var_dump($f->file($test_file));
+
+?>
+===DONE===
+--EXPECTF--
+string(%d) "JPEG image data, JFIF standard 1.01, comment: "%S""
+===DONE===