Skip to content

Commit b2c8abe

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Better overflow check for entity decoding
2 parents 22d2a80 + 18599f9 commit b2c8abe

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
@@ -87,6 +87,7 @@
8787

8888
#include <stddef.h>
8989
#include <string.h>
90+
#include <limits.h>
9091

9192
#include "mbfilter.h"
9293
#include "mbfl_filter_output.h"
@@ -2474,12 +2475,12 @@ collector_decode_htmlnumericentity(int c, void *data)
24742475
s = 0;
24752476
f = 0;
24762477
if (c >= 0x30 && c <= 0x39) { /* '0' - '9' */
2477-
if (pc->digit > 9) {
2478+
s = pc->cache;
2479+
if (s > INT_MAX/10) {
24782480
pc->status = 0;
2479-
s = pc->cache;
24802481
f = 1;
24812482
} else {
2482-
s = pc->cache*10 + c - 0x30;
2483+
s = s*10 + (c - 0x30);
24832484
pc->cache = s;
24842485
pc->digit++;
24852486
}

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

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

0 commit comments

Comments
 (0)