Skip to content

Commit 9d0db2e

Browse files
committed
Fixed bug #81298
Creation of the filter may fail for some special encodings, for which detection is not supported.
1 parent dcf5e5b commit 9d0db2e

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.0beta2
44

5+
- Mbstring:
6+
. Fixed bug #81298 (mb_detect_encoding() segfaults when 7bit encoding is
7+
specified). (Nikita)
8+
59
- MySQLnd:
610
. Fixed bug #63327 (Crash (Bus Error) in mysqlnd due to wrong alignment).
711
(Nikita)

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,17 @@ mbfl_encoding_detector *mbfl_encoding_detector_new(const mbfl_encoding **elist,
315315

316316
mbfl_encoding_detector *identd = emalloc(sizeof(mbfl_encoding_detector));
317317
identd->filter_list = ecalloc(elistsz, sizeof(mbfl_convert_filter*));
318+
319+
int filter_list_size = 0;
318320
for (int i = 0; i < elistsz; i++) {
319-
identd->filter_list[i] = mbfl_convert_filter_new(elist[i], &mbfl_encoding_wchar,
321+
mbfl_convert_filter *filter = mbfl_convert_filter_new(elist[i], &mbfl_encoding_wchar,
320322
mbfl_estimate_encoding_likelihood, NULL, &identd->filter_list[i]);
321-
identd->filter_list[i]->opaque = (void*)0;
323+
if (filter) {
324+
identd->filter_list[filter_list_size++] = filter;
325+
filter->opaque = (void*)0;
326+
}
322327
}
323-
identd->filter_list_size = elistsz;
328+
identd->filter_list_size = filter_list_size;
324329
identd->strict = strict;
325330
return identd;
326331
}

ext/mbstring/tests/bug81298.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #81298: mb_detect_encoding() segfaults when 7bit encoding is specified
3+
--FILE--
4+
<?php
5+
6+
var_dump(mb_detect_encoding("foobar", "7bit"));
7+
var_dump(mb_detect_encoding("foobar", "7bit,ascii"));
8+
9+
?>
10+
--EXPECT--
11+
bool(false)
12+
string(5) "ASCII"

0 commit comments

Comments
 (0)