com php-src: Fixed bug #68735 fileinfo out-of-bounds memory access: NEWS ext/fileinfo/libmagic/softmagic.c ext/fileinfo/tests/bug68735.jpg
ext/fileinfo/tests/bug68735.phpt

From: Date: Sun, 04 Jan 2015 13:20:21 +0000
Subject: com php-src: Fixed bug #68735 fileinfo out-of-bounds memory access: NEWS ext/fileinfo/libmagic/softmagic.c ext/fileinfo/tests/bug68735.jpg
ext/fileinfo/tests/bug68735.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-83959@lists.php.net to get a copy of this message
Commit: ede59c8feb4b80e1b94e4abdaa0711051e2912ab Author: Anatol Belski <ab@php.net> Sun, 4 Jan 2015 14:20:21 +0100 Parents: 919abf0cb132cc06c3a0be311af3069bd4be09ce Branches: PHP-5.4 PHP-5.5 PHP-5.6 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ede59c8feb4b80e1b94e4abdaa0711051e2912ab Log: Fixed bug #68735 fileinfo out-of-bounds memory access Bugs: https://bugs.php.net/68735 Changed paths: M NEWS M ext/fileinfo/libmagic/softmagic.c A ext/fileinfo/tests/bug68735.jpg A ext/fileinfo/tests/bug68735.phpt Diff: diff --git a/NEWS b/NEWS index fa57ef3..cbbdb5e 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,13 @@ PHP NEWS - CGI: . Fix bug #68618 (out of bounds read crashes php-cgi). (Stas) +- Fileinfo: + . Removed readelf.c and related code from libmagic sources + (Remi, Anatol) + . Fixed bug #68735 (fileinfo out-of-bounds memory access). + (Anatol) + + 18 Dec 2014 PHP 5.4.36 - Core: diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c index 7e0c856..e7b7855 100644 --- a/ext/fileinfo/libmagic/softmagic.c +++ b/ext/fileinfo/libmagic/softmagic.c @@ -884,14 +884,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 0000000..633bdb9 Binary files /dev/null and b/ext/fileinfo/tests/bug68735.jpg differ diff --git a/ext/fileinfo/tests/bug68735.phpt b/ext/fileinfo/tests/bug68735.phpt new file mode 100644 index 0000000..f86109c --- /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===

« previous php.cvs (#83959) next »