Skip to content

Commit bf5a802

Browse files
Marcus Schwarznikic
authored andcommitted
Fixed bug #76532 (excessive memory usage in mb_strimwidth)
1 parent f6430e3 commit bf5a802

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ PHP NEWS
1515
. Fixed bug #73342 (Vulnerability in php-fpm by changing stdin to
1616
non-blocking). (Nikita)
1717

18+
- mbstring:
19+
. Fixed bug #76532 (Integer overflow and excessive memory usage
20+
in mb_strimwidth). (MarcusSchwarz)
21+
1822
- phpdbg:
1923
. Fix arginfo wrt. optional/required parameters. (cmb)
2024

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ mbfl_strimwidth(
18751875
mbfl_string_init(result);
18761876
result->no_language = string->no_language;
18771877
result->no_encoding = string->no_encoding;
1878-
mbfl_memory_device_init(&pc.device, width, 0);
1878+
mbfl_memory_device_init(&pc.device, MIN(string->len, width), 0);
18791879

18801880
/* output code filter */
18811881
pc.decoder = mbfl_convert_filter_new(

ext/mbstring/libmbfl/mbfl/mbfilter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@
113113
#define MBFL_OUTPUTFILTER_ILLEGAL_MODE_LONG 2
114114
#define MBFL_OUTPUTFILTER_ILLEGAL_MODE_ENTITY 3
115115

116+
/*
117+
* convenience macros
118+
*/
119+
#ifndef MIN
120+
#define MIN(a,b) ((a)<(b)?(a):(b))
121+
#endif
122+
116123
/*
117124
* buffering converter
118125
*/

ext/mbstring/tests/bug76532.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #76532 (Integer overflow and excessive memory usage in mb_strimwidth)
3+
--SKIPIF--
4+
<?php require 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
$string_to_trim = '得很幸福。有一天,一个长得很丑的老人带着一只木马来到王';
8+
$width = 2147483647;
9+
var_dump(mb_strimwidth($string_to_trim, 0, $width));
10+
?>
11+
--EXPECT--
12+
string(81) "得很幸福。有一天,一个长得很丑的老人带着一只木马来到王"

0 commit comments

Comments
 (0)