Skip to content

Commit 1119c4d

Browse files
committed
Allow ill-formed unicode escapes in decoder
1 parent 32d54ac commit 1119c4d

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

ext/json/json_scanner.re

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,13 @@ std:
213213
s->str_esc += 4;
214214
PHP_JSON_CONDITION_GOTO(STR_P1);
215215
}
216-
<STR_P1>UTF16_3 {
217-
s->str_esc += 3;
218-
PHP_JSON_CONDITION_GOTO(STR_P1);
219-
}
220216
<STR_P1>UTF16_4 {
221217
s->str_esc += 8;
222218
PHP_JSON_CONDITION_GOTO(STR_P1);
223219
}
224220
<STR_P1>UCS2 {
225-
s->errcode = PHP_JSON_ERROR_UTF16;
226-
return PHP_JSON_T_ERROR;
221+
s->str_esc += 3;
222+
PHP_JSON_CONDITION_GOTO(STR_P1);
227223
}
228224
<STR_P1>ESC {
229225
s->str_esc++;
@@ -276,15 +272,6 @@ std:
276272
s->str_start = s->cursor;
277273
PHP_JSON_CONDITION_GOTO(STR_P2);
278274
}
279-
<STR_P2>UTF16_3 {
280-
int utf16 = php_json_ucs2_to_int(s, 4);
281-
PHP_JSON_SCANNER_COPY_UTF();
282-
*(s->pstr++) = (char) (0xe0 | (utf16 >> 12));
283-
*(s->pstr++) = (char) (0x80 | ((utf16 >> 6) & 0x3f));
284-
*(s->pstr++) = (char) (0x80 | (utf16 & 0x3f));
285-
s->str_start = s->cursor;
286-
PHP_JSON_CONDITION_GOTO(STR_P2);
287-
}
288275
<STR_P2>UTF16_4 {
289276
int utf32, utf16_hi, utf16_lo;
290277
utf16_hi = php_json_ucs2_to_int(s, 4);
@@ -298,6 +285,15 @@ std:
298285
s->str_start = s->cursor;
299286
PHP_JSON_CONDITION_GOTO(STR_P2);
300287
}
288+
<STR_P2>UCS2 {
289+
int utf16 = php_json_ucs2_to_int(s, 4);
290+
PHP_JSON_SCANNER_COPY_UTF();
291+
*(s->pstr++) = (char) (0xe0 | (utf16 >> 12));
292+
*(s->pstr++) = (char) (0x80 | ((utf16 >> 6) & 0x3f));
293+
*(s->pstr++) = (char) (0x80 | (utf16 & 0x3f));
294+
s->str_start = s->cursor;
295+
PHP_JSON_CONDITION_GOTO(STR_P2);
296+
}
301297
<STR_P2>ESCPREF {
302298
char esc;
303299
PHP_JSON_SCANNER_COPY_ESC();

0 commit comments

Comments
 (0)