Skip to content

Commit ede59c8

Browse files
committed
Fixed bug #68735 fileinfo out-of-bounds memory access
1 parent 919abf0 commit ede59c8

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ PHP NEWS
44
- CGI:
55
. Fix bug #68618 (out of bounds read crashes php-cgi). (Stas)
66

7+
- Fileinfo:
8+
. Removed readelf.c and related code from libmagic sources
9+
(Remi, Anatol)
10+
. Fixed bug #68735 (fileinfo out-of-bounds memory access).
11+
(Anatol)
12+
13+
714
18 Dec 2014 PHP 5.4.36
815

916
- Core:

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)