Skip to content

Commit 18599f9

Browse files
committed
Better overflow check for entity decoding
Check for multiplication overflow rather than number of digits.
1 parent 085371b commit 18599f9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686

8787
#include <stddef.h>
8888
#include <string.h>
89+
#include <limits.h>
8990

9091
#include "mbfilter.h"
9192
#include "mbfl_filter_output.h"
@@ -2552,12 +2553,12 @@ collector_decode_htmlnumericentity(int c, void *data)
25522553
s = 0;
25532554
f = 0;
25542555
if (c >= 0x30 && c <= 0x39) { /* '0' - '9' */
2555-
if (pc->digit > 9) {
2556+
s = pc->cache;
2557+
if (s > INT_MAX/10) {
25562558
pc->status = 0;
2557-
s = pc->cache;
25582559
f = 1;
25592560
} else {
2560-
s = pc->cache*10 + c - 0x30;
2561+
s = s*10 + (c - 0x30);
25612562
pc->cache = s;
25622563
pc->digit++;
25632564
}

ext/mbstring/tests/mb_decode_numericentity.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ echo mb_decode_numericentity($str2, $convmap, "UTF-8")."\n";
1616
echo mb_decode_numericentity($str3, $convmap, "UTF-8")."\n";
1717

1818
echo mb_decode_numericentity('&#1000000000', $convmap), "\n";
19+
echo mb_decode_numericentity('&#9000000000', $convmap), "\n";
1920
echo mb_decode_numericentity('&#10000000000', $convmap), "\n";
2021
echo mb_decode_numericentity('&#100000000000', $convmap), "\n";
2122

@@ -25,5 +26,6 @@ echo mb_decode_numericentity('&#100000000000', $convmap), "\n";
2526
ƒΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϑϒϖ•…′″‾⁄℘ℑℜ™ℵ←↑→↓↔↵⇐⇑⇒⇓⇔∀∂∃∅∇∈∉∋∏∑−∗√∝∞∠∧∨∩∪∫∴∼≅≈≠≡≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈⌉⌊⌋〈〉◊♠♣♥♦
2627
aŒbœcŠdše€fg
2728
&#1000000000
29+
&#9000000000
2830
&#10000000000
2931
&#100000000000

0 commit comments

Comments
 (0)