mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Have std/json reject control characters in strings
This commit is contained in:
1 parent
0711f23fed
commit
27036043ae
2 files changed
+40
-14
No files matched your search
@@ -18362,17 +18362,33 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
}
|
||||
v_c = wuffs_base__load_u8be(iop_a_src);
|
||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||
if (v_c == 34) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291456)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
goto label_2_break;
|
||||
if (v_c <= 34) {
|
||||
if (v_c == 34) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291456))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
goto label_2_break;
|
||||
} else if (v_c < 32) {
|
||||
if (v_string_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457))
|
||||
<< WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(((uint64_t)(v_string_length))))
|
||||
<< WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
v_string_length = 0;
|
||||
}
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
} else if (v_c == 92) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
} else if (v_string_length >= 65534) {
|
||||
}
|
||||
if (v_string_length >= 65534) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(6291457)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
|
||||
(((uint64_t)(65535)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
|
||||
@@ -172,21 +172,31 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
c = args.src.peek_u8()
|
||||
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||
|
||||
if c == 0x22 { // 0x22 is '"'.
|
||||
args.dst.write_fast_token!(value: 0x60_0000, length: string_length as base.u64)
|
||||
string_length = 0
|
||||
break.string_loop
|
||||
if c <= 0x22 { // 0x22 is '"'.
|
||||
if c == 0x22 { // 0x22 is '"'.
|
||||
args.dst.write_fast_token!(value: 0x60_0000, length: string_length as base.u64)
|
||||
string_length = 0
|
||||
break.string_loop
|
||||
|
||||
} else if c < 0x20 { // 0x20 is ' '.
|
||||
if string_length > 0 {
|
||||
args.dst.write_fast_token!(value: 0x60_0001, length: string_length as base.u64)
|
||||
string_length = 0
|
||||
}
|
||||
return "#bad input"
|
||||
}
|
||||
|
||||
} else if c == 0x5C { // 0x5C is '\\'.
|
||||
// TODO: escapes.
|
||||
return "#bad input"
|
||||
|
||||
} else if string_length >= 0xFFFE {
|
||||
}
|
||||
|
||||
if string_length >= 0xFFFE {
|
||||
args.dst.write_fast_token!(value: 0x60_0001, length: 0xFFFF)
|
||||
string_length = 0
|
||||
continue.string_loop
|
||||
}
|
||||
|
||||
string_length += 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user