File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -639,9 +639,16 @@ int php_json_scan(php_json_scanner *s)
639
639
yy80 :
640
640
{
641
641
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
+ }
643
651
s -> utf8_invalid = 1 ;
644
- s -> utf8_invalid_count += utf8_addition - 1 ;
645
652
PHP_JSON_CONDITION_GOTO (STR_P1 );
646
653
}
647
654
s -> errcode = PHP_JSON_ERROR_UTF8 ;
Original file line number Diff line number Diff line change @@ -281,9 +281,16 @@ std:
281
281
<STR_P1>UTF8 { PHP_JSON_CONDITION_GOTO(STR_P1); }
282
282
<STR_P1>ANY {
283
283
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
+ }
285
293
s->utf8_invalid = 1;
286
- s->utf8_invalid_count += utf8_addition - 1;
287
294
PHP_JSON_CONDITION_GOTO(STR_P1);
288
295
}
289
296
s->errcode = PHP_JSON_ERROR_UTF8;
You can’t perform that action at this time.
0 commit comments