Skip to content

Commit 7233198

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: updated NEWS updated NEWS Fixed bug #68735 fileinfo out-of-bounds memory access
2 parents f6abcd9 + 5c0f032 commit 7233198

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
@@ -920,14 +920,17 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
920920
size_t sz = file_pstring_length_size(m);
921921
char *ptr1 = p->s, *ptr2 = ptr1 + sz;
922922
size_t len = file_pstring_get_length(m, ptr1);
923-
if (len >= sizeof(p->s)) {
923+
sz = sizeof(p->s) - sz; /* maximum length of string */
924+
if (len >= sz) {
924925
/*
925926
* The size of the pascal string length (sz)
926927
* is 1, 2, or 4. We need at least 1 byte for NUL
927928
* termination, but we've already truncated the
928929
* string by p->s, so we need to deduct sz.
930+
* Because we can use one of the bytes of the length
931+
* after we shifted as NUL termination.
929932
*/
930-
len = sizeof(p->s) - sz;
933+
len = sz;
931934
}
932935
while (len--)
933936
*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)