mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.5'
This commit is contained in:
2
NEWS
2
NEWS
@@ -56,6 +56,8 @@ PHP NEWS
|
||||
. Added GB18030-2022 to default encoding list for zh-CN. (HeRaNO)
|
||||
. Fixed bug GH-20836 (Stack overflow in mb_convert_variables with
|
||||
recursive array references). (alexandre-daubois)
|
||||
. Fixed bug GH-21223; mb_guess_encoding no longer crashes when passed huge
|
||||
list of candidate encodings (with 200,000+ entries). (Jordi Kroon)
|
||||
|
||||
- Opcache:
|
||||
. Fixed bug GH-20051 (apache2 shutdowns when restart is requested during
|
||||
|
||||
@@ -3414,8 +3414,9 @@ MBSTRING_API const mbfl_encoding* mb_guess_encoding_for_strings(const unsigned c
|
||||
return *elist;
|
||||
}
|
||||
|
||||
/* Allocate on stack; when we return, this array is automatically freed */
|
||||
struct candidate *array = alloca(elist_size * sizeof(struct candidate));
|
||||
/* Allocate on stack or heap */
|
||||
ALLOCA_FLAG(use_heap)
|
||||
struct candidate *array = do_alloca(elist_size * sizeof(struct candidate), use_heap);
|
||||
elist_size = init_candidate_array(array, elist_size, elist, strings, str_lengths, n, strict, order_significant);
|
||||
|
||||
while (n--) {
|
||||
@@ -3423,6 +3424,7 @@ MBSTRING_API const mbfl_encoding* mb_guess_encoding_for_strings(const unsigned c
|
||||
elist_size = count_demerits(array, elist_size, strict);
|
||||
if (elist_size == 0) {
|
||||
/* All candidates were eliminated */
|
||||
free_alloca(array, use_heap);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -3434,7 +3436,10 @@ MBSTRING_API const mbfl_encoding* mb_guess_encoding_for_strings(const unsigned c
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
return array[best].enc;
|
||||
|
||||
const mbfl_encoding *result = array[best].enc;
|
||||
free_alloca(array, use_heap);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* When doing 'strict' detection, any string which is invalid in the candidate encoding
|
||||
|
||||
19
ext/mbstring/tests/gh21223.phpt
Normal file
19
ext/mbstring/tests/gh21223.phpt
Normal file
@@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
GH-21223 (Stack overflow in mb_guess_encoding called via mb_detect_encoding)
|
||||
--EXTENSIONS--
|
||||
mbstring
|
||||
--FILE--
|
||||
<?php
|
||||
$str = "hello";
|
||||
|
||||
$list = [];
|
||||
for ($i = 0; $i < 500000; $i++) {
|
||||
$list[] = "UTF-8";
|
||||
}
|
||||
|
||||
var_dump(mb_detect_encoding($str, $list, false));
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECT--
|
||||
string(5) "UTF-8"
|
||||
Done
|
||||
Reference in New Issue
Block a user