Skip to content

Commit 5fe54db

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Fixed bug #68735 fileinfo out-of-bounds memory access
2 parents b644dcf + ede59c8 commit 5fe54db

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ext/fileinfo/libmagic/softmagic.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,14 +884,17 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
884884
size_t sz = file_pstring_length_size(m);
885885
char *ptr1 = p->s, *ptr2 = ptr1 + sz;
886886
size_t len = file_pstring_get_length(m, ptr1);
887-
if (len >= sizeof(p->s)) {
887+
sz = sizeof(p->s) - sz; /* maximum length of string */
888+
if (len >= sz) {
888889
/*
889890
* The size of the pascal string length (sz)
890891
* is 1, 2, or 4. We need at least 1 byte for NUL
891892
* termination, but we've already truncated the
892893
* string by p->s, so we need to deduct sz.
894+
* Because we can use one of the bytes of the length
895+
* after we shifted as NUL termination.
893896
*/
894-
len = sizeof(p->s) - sz;
897+
len = sz;
895898
}
896899
while (len--)
897900
*ptr1++ = *ptr2++;

ext/fileinfo/tests/bug68735.jpg

24 Bytes
Loading

ext/fileinfo/tests/bug68735.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #68735 fileinfo out-of-bounds memory access
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$test_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug68735.jpg";
8+
$f = new finfo;
9+
10+
var_dump($f->file($test_file));
11+
12+
?>
13+
===DONE===
14+
--EXPECTF--
15+
string(%d) "JPEG image data, JFIF standard 1.01, comment: "%S""
16+
===DONE===

0 commit comments

Comments
 (0)