Skip to content

Commit 9891f08

Browse files
committed
Merge branch 'PHP-7.2'
2 parents cf8c9fc + f5b4cb7 commit 9891f08

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

ext/json/json_scanner.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,16 @@ int php_json_scan(php_json_scanner *s)
639639
yy80:
640640
{
641641
if (s->options & (PHP_JSON_INVALID_UTF8_IGNORE | PHP_JSON_INVALID_UTF8_SUBSTITUTE)) {
642-
int utf8_addition = (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) ? 3 : 0;
642+
if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
643+
if (s->utf8_invalid_count > INT_MAX - 2) {
644+
s->errcode = PHP_JSON_ERROR_UTF8;
645+
return PHP_JSON_T_ERROR;
646+
}
647+
s->utf8_invalid_count += 2;
648+
} else {
649+
s->utf8_invalid_count--;
650+
}
643651
s->utf8_invalid = 1;
644-
s->utf8_invalid_count += utf8_addition - 1;
645652
PHP_JSON_CONDITION_GOTO(STR_P1);
646653
}
647654
s->errcode = PHP_JSON_ERROR_UTF8;

ext/json/json_scanner.re

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,16 @@ std:
281281
<STR_P1>UTF8 { PHP_JSON_CONDITION_GOTO(STR_P1); }
282282
<STR_P1>ANY {
283283
if (s->options & (PHP_JSON_INVALID_UTF8_IGNORE | PHP_JSON_INVALID_UTF8_SUBSTITUTE)) {
284-
int utf8_addition = (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) ? 3 : 0;
284+
if (s->options & PHP_JSON_INVALID_UTF8_SUBSTITUTE) {
285+
if (s->utf8_invalid_count > INT_MAX - 2) {
286+
s->errcode = PHP_JSON_ERROR_UTF8;
287+
return PHP_JSON_T_ERROR;
288+
}
289+
s->utf8_invalid_count += 2;
290+
} else {
291+
s->utf8_invalid_count--;
292+
}
285293
s->utf8_invalid = 1;
286-
s->utf8_invalid_count += utf8_addition - 1;
287294
PHP_JSON_CONDITION_GOTO(STR_P1);
288295
}
289296
s->errcode = PHP_JSON_ERROR_UTF8;

0 commit comments

Comments
 (0)