com php-src: catch up with the previous cve-2014-3538 patch: ext/fileinfo/libmagic/softmagic.c

From: Date: Sun, 08 Mar 2015 18:47:33 +0000
Subject: com php-src: catch up with the previous cve-2014-3538 patch: ext/fileinfo/libmagic/softmagic.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85343@lists.php.net to get a copy of this message
Commit: 9603f16f995154a858d7e0b31eff3a9b79f88ff7 Author: Anatol Belski <ab@php.net> Sun, 8 Mar 2015 13:09:58 +0100 Parents: f39a8517e002d33ace29ec0ba15acb30c9fecbb3 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9603f16f995154a858d7e0b31eff3a9b79f88ff7 Log: catch up with the previous cve-2014-3538 patch Changed paths: M ext/fileinfo/libmagic/softmagic.c Diff: diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c index ef819c2..9ac177c 100644 --- a/ext/fileinfo/libmagic/softmagic.c +++ b/ext/fileinfo/libmagic/softmagic.c @@ -1081,7 +1081,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, const char *last; /* end of search region */ const char *buf; /* start of search region */ const char *end; - size_t lines, linecnt, bytecnt; + size_t lines, linecnt, bytecnt, bytecnt_max; if (s == NULL) { ms->search.s_len = 0; @@ -1097,8 +1097,15 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, bytecnt = m->str_range; } - if (bytecnt == 0 || bytecnt > nbytes - offset) - bytecnt = nbytes - offset; + /* XXX bytecnt_max is to be kept for PHP, see cve-2014-3538. + PCRE might stuck if the input buffer is too big. To ensure + the correctness, the check for bytecnt > nbytes is also + kept (might be abundant). */ + bytecnt_max = nbytes - offset; + bytecnt_max = bytecnt_max > (1 << 14) ? (1 << 14) : bytecnt_max; + bytecnt_max = bytecnt > nbytes ? nbytes : bytecnt_max; + if (bytecnt == 0 || bytecnt > bytecnt_max) + bytecnt = bytecnt_max; buf = RCAST(const char *, s) + offset; end = last = RCAST(const char *, s) + bytecnt;

« previous php.cvs (#85343) next »