Skip to content

Commit c621182

Browse files
committed
Backport 7f5f460 for 7.2
1 parent 0afc818 commit c621182

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

ext/fileinfo/libmagic/apprentice.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,18 +2524,19 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
25242524
return -1;
25252525
}
25262526
if (m->type == FILE_REGEX) {
2527-
/* XXX do we need this? */
2528-
/*zval pattern;
2527+
zval pattern;
25292528
int options = 0;
25302529
pcre_cache_entry *pce;
25312530

25322531
convert_libmagic_pattern(&pattern, m->value.s, strlen(m->value.s), options);
25332532

25342533
if ((pce = pcre_get_compiled_regex_cache(Z_STR(pattern))) == NULL) {
2534+
zval_dtor(&pattern);
25352535
return -1;
25362536
}
2537+
zval_dtor(&pattern);
25372538

2538-
return 0;*/
2539+
return 0;
25392540
}
25402541
return 0;
25412542
case FILE_FLOAT:

ext/fileinfo/libmagic/softmagic.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,28 +1203,21 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
12031203
return 0;
12041204
}
12051205

1206-
/* bytecnt checks are to be kept for PHP, see cve-2014-3538.
1207-
PCRE might get stuck if the input buffer is too big. */
1208-
linecnt = m->str_range;
1209-
bytecnt = linecnt * 80;
1210-
1211-
if (bytecnt == 0) {
1212-
bytecnt = 1 << 14;
1206+
if (m->str_flags & REGEX_LINE_COUNT) {
1207+
linecnt = m->str_range;
1208+
bytecnt = linecnt * 80;
1209+
} else {
1210+
linecnt = 0;
1211+
bytecnt = m->str_range;
12131212
}
12141213

1215-
if (bytecnt > nbytes) {
1216-
bytecnt = nbytes;
1217-
}
1218-
if (offset > bytecnt) {
1219-
offset = bytecnt;
1220-
}
1221-
if (s == NULL) {
1222-
ms->search.s_len = 0;
1223-
ms->search.s = NULL;
1224-
return 0;
1225-
}
1214+
if (bytecnt == 0 || bytecnt > nbytes - offset)
1215+
bytecnt = nbytes - offset;
1216+
if (bytecnt > ms->regex_max)
1217+
bytecnt = ms->regex_max;
1218+
12261219
buf = RCAST(const char *, s) + offset;
1227-
end = last = RCAST(const char *, s) + bytecnt;
1220+
end = last = RCAST(const char *, s) + bytecnt + offset;
12281221
/* mget() guarantees buf <= last */
12291222
for (lines = linecnt, b = buf; lines && b < end &&
12301223
((b = CAST(const char *,

0 commit comments

Comments
 (0)