com php-src: Fixed bug #69320 libmagic crash when running laravel tests: ext/fileinfo/libmagic/softmagic.c
| From: | Anatol Belski | Date: | Sun, 29 Mar 2015 15:42:59 +0000 |
| Subject: | com php-src: Fixed bug #69320 libmagic crash when running laravel tests: ext/fileinfo/libmagic/softmagic.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85923@lists.php.net to get a copy of this message | ||
Commit: aeabea4aa91af64db1fa1a592b92496fb5e293ba
Author: Anatol Belski <ab@php.net> Sun, 29 Mar 2015 17:42:59 +0200
Parents: 2accf544cbd4bbe9df5f8990fbb80a98f6879086
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=aeabea4aa91af64db1fa1a592b92496fb5e293ba
Log:
Fixed bug #69320 libmagic crash when running laravel tests
Basically reverted the part of the new patch to what we have in 5.6
as the current change seems to have bad side effects. Hovere the
in buffer used for PCRE is still doubled (1 << 14), this might or
might not be optimal, so lets observe.
Bugs:
https://bugs.php.net/69320
Changed paths:
M ext/fileinfo/libmagic/softmagic.c
Diff:
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
index 9ac177c..ddf7370 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, bytecnt_max;
+ size_t lines, linecnt, bytecnt;
if (s == NULL) {
ms->search.s_len = 0;
@@ -1089,23 +1089,18 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
return 0;
}
- if (m->str_flags & REGEX_LINE_COUNT) {
- linecnt = m->str_range;
- bytecnt = linecnt * 80;
- } else {
- linecnt = 0;
- bytecnt = m->str_range;
+ /* bytecnt checks are to be kept for PHP, see cve-2014-3538.
+ PCRE might get stuck if the input buffer is too big. */
+ linecnt = m->str_range;
+ bytecnt = linecnt * 80;
+
+ if (bytecnt == 0) {
+ bytecnt = 1 << 14;
}
- /* 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;
+ if (bytecnt > nbytes) {
+ bytecnt = nbytes;
+ }
buf = RCAST(const char *, s) + offset;
end = last = RCAST(const char *, s) + bytecnt;