mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Raise json.DECODER_NUMBER_LENGTH_MAX_INCL to 2047
This commit is contained in:
1 parent
2a7e1ed175
commit
b9f69264a0
4 files changed
+87
-84
No files matched your search
@@ -6995,7 +6995,7 @@ extern const char wuffs_json__error__unsupported_recursion_depth[];
|
|||||||
|
|
||||||
#define WUFFS_JSON__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL 1
|
#define WUFFS_JSON__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL 1
|
||||||
|
|
||||||
#define WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 100
|
#define WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 2048
|
||||||
|
|
||||||
#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1225364480
|
#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1225364480
|
||||||
|
|
||||||
@@ -23250,7 +23250,7 @@ const char wuffs_json__error__internal_error_inconsistent_i_o[] = "#json: intern
|
|||||||
|
|
||||||
// ---------------- Private Consts
|
// ---------------- Private Consts
|
||||||
|
|
||||||
#define WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL 99
|
#define WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL 2047
|
||||||
|
|
||||||
static const uint8_t
|
static const uint8_t
|
||||||
WUFFS_JSON__LUT_BACKSLASHES[256]WUFFS_BASE__POTENTIALLY_UNUSED = {
|
WUFFS_JSON__LUT_BACKSLASHES[256]WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||||
@@ -24375,12 +24375,12 @@ wuffs_json__decoder__decode_tokens(
|
|||||||
if (a_src) {
|
if (a_src) {
|
||||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||||
}
|
}
|
||||||
v_number_status = (v_number_length >> 8);
|
v_number_status = (v_number_length >> 12);
|
||||||
v_vminor = 10486787;
|
v_vminor = 10486787;
|
||||||
if ((v_number_length & 128) != 0) {
|
if ((v_number_length & 2048) != 0) {
|
||||||
v_vminor = 10486785;
|
v_vminor = 10486785;
|
||||||
}
|
}
|
||||||
v_number_length = (v_number_length & 127);
|
v_number_length = (v_number_length & 2047);
|
||||||
if (v_number_status == 0) {
|
if (v_number_status == 0) {
|
||||||
*iop_a_dst++ = wuffs_base__make_token(
|
*iop_a_dst++ = wuffs_base__make_token(
|
||||||
(((uint64_t)(v_vminor)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
(((uint64_t)(v_vminor)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||||
@@ -24707,7 +24707,7 @@ wuffs_json__decoder__decode_number(
|
|||||||
v_n = 0;
|
v_n = 0;
|
||||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||||
if ( ! (a_src && a_src->meta.closed)) {
|
if ( ! (a_src && a_src->meta.closed)) {
|
||||||
v_n |= 768;
|
v_n |= 12288;
|
||||||
}
|
}
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
@@ -24718,9 +24718,9 @@ wuffs_json__decoder__decode_number(
|
|||||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||||
if ( ! (a_src && a_src->meta.closed)) {
|
if ( ! (a_src && a_src->meta.closed)) {
|
||||||
v_n |= 768;
|
v_n |= 12288;
|
||||||
}
|
}
|
||||||
v_n |= 256;
|
v_n |= 4096;
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
v_c = wuffs_base__load_u8be__no_bounds_check(iop_a_src);
|
v_c = wuffs_base__load_u8be__no_bounds_check(iop_a_src);
|
||||||
@@ -24736,26 +24736,26 @@ wuffs_json__decoder__decode_number(
|
|||||||
if (a_src) {
|
if (a_src) {
|
||||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||||
}
|
}
|
||||||
if (v_n > 99) {
|
if (v_n > 2047) {
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||||
if ( ! (a_src && a_src->meta.closed)) {
|
if ( ! (a_src && a_src->meta.closed)) {
|
||||||
v_n |= 768;
|
v_n |= 12288;
|
||||||
}
|
}
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
v_c = wuffs_base__load_u8be__no_bounds_check(iop_a_src);
|
v_c = wuffs_base__load_u8be__no_bounds_check(iop_a_src);
|
||||||
if (v_c != 46) {
|
if (v_c != 46) {
|
||||||
} else {
|
} else {
|
||||||
if (v_n >= 99) {
|
if (v_n >= 2047) {
|
||||||
v_n |= 512;
|
v_n |= 8192;
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
v_n += 1;
|
v_n += 1;
|
||||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||||
v_floating_point = 128;
|
v_floating_point = 2048;
|
||||||
if (a_src) {
|
if (a_src) {
|
||||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
}
|
}
|
||||||
@@ -24763,12 +24763,12 @@ wuffs_json__decoder__decode_number(
|
|||||||
if (a_src) {
|
if (a_src) {
|
||||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||||
}
|
}
|
||||||
if (v_n > 99) {
|
if (v_n > 2047) {
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||||
if ( ! (a_src && a_src->meta.closed)) {
|
if ( ! (a_src && a_src->meta.closed)) {
|
||||||
v_n |= 768;
|
v_n |= 12288;
|
||||||
}
|
}
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
@@ -24777,25 +24777,25 @@ wuffs_json__decoder__decode_number(
|
|||||||
if ((v_c != 69) && (v_c != 101)) {
|
if ((v_c != 69) && (v_c != 101)) {
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
if (v_n >= 99) {
|
if (v_n >= 2047) {
|
||||||
v_n |= 512;
|
v_n |= 8192;
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
v_n += 1;
|
v_n += 1;
|
||||||
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
(iop_a_src += 1, wuffs_base__make_empty_struct());
|
||||||
v_floating_point = 128;
|
v_floating_point = 2048;
|
||||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||||
if ( ! (a_src && a_src->meta.closed)) {
|
if ( ! (a_src && a_src->meta.closed)) {
|
||||||
v_n |= 768;
|
v_n |= 12288;
|
||||||
}
|
}
|
||||||
v_n |= 256;
|
v_n |= 4096;
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
v_c = wuffs_base__load_u8be__no_bounds_check(iop_a_src);
|
v_c = wuffs_base__load_u8be__no_bounds_check(iop_a_src);
|
||||||
if ((v_c != 43) && (v_c != 45)) {
|
if ((v_c != 43) && (v_c != 45)) {
|
||||||
} else {
|
} else {
|
||||||
if (v_n >= 99) {
|
if (v_n >= 2047) {
|
||||||
v_n |= 512;
|
v_n |= 8192;
|
||||||
goto label__goto_done__break;
|
goto label__goto_done__break;
|
||||||
}
|
}
|
||||||
v_n += 1;
|
v_n += 1;
|
||||||
@@ -24842,7 +24842,7 @@ wuffs_json__decoder__decode_digits(
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||||
if ( ! (a_src && a_src->meta.closed)) {
|
if ( ! (a_src && a_src->meta.closed)) {
|
||||||
v_n |= 768;
|
v_n |= 12288;
|
||||||
}
|
}
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
}
|
}
|
||||||
@@ -24850,8 +24850,8 @@ wuffs_json__decoder__decode_digits(
|
|||||||
if (0 == WUFFS_JSON__LUT_DECIMAL_DIGITS[v_c]) {
|
if (0 == WUFFS_JSON__LUT_DECIMAL_DIGITS[v_c]) {
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
}
|
}
|
||||||
if (v_n >= 99) {
|
if (v_n >= 2047) {
|
||||||
v_n |= 512;
|
v_n |= 8192;
|
||||||
goto label__0__break;
|
goto label__0__break;
|
||||||
}
|
}
|
||||||
v_n += 1;
|
v_n += 1;
|
||||||
@@ -24859,7 +24859,7 @@ wuffs_json__decoder__decode_digits(
|
|||||||
}
|
}
|
||||||
label__0__break:;
|
label__0__break:;
|
||||||
if (v_n == a_n) {
|
if (v_n == a_n) {
|
||||||
v_n |= 256;
|
v_n |= 4096;
|
||||||
}
|
}
|
||||||
if (a_src) {
|
if (a_src) {
|
||||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ pub const DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL : base.u64 = 1
|
|||||||
// maximum possible src.meta.ri and src.meta.wi values). It is a property of
|
// maximum possible src.meta.ri and src.meta.wi values). It is a property of
|
||||||
// the backing array's length, not the length of the JSON-formatted input per
|
// the backing array's length, not the length of the JSON-formatted input per
|
||||||
// se. It is perfectly valid to decode "[1,2]" (of length 5) as JSON, as long
|
// se. It is perfectly valid to decode "[1,2]" (of length 5) as JSON, as long
|
||||||
// as that content is placed in an io_buffer whose data.len is at least 100.
|
// as that content is placed in an io_buffer whose data.len is at least 2048.
|
||||||
pub const DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL : base.u64 = 100
|
pub const DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL : base.u64 = 2048
|
||||||
|
|
||||||
// DECODER_NUMBER_LENGTH_MAX_INCL is the longest supported byte length for a
|
// DECODER_NUMBER_LENGTH_MAX_INCL is the longest supported byte length for a
|
||||||
// JSON number. Unlike JSON strings, this package's tokenizer never splits a
|
// JSON number. Unlike JSON strings, this package's tokenizer never splits a
|
||||||
@@ -52,7 +52,7 @@ pub const DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL : base.u64 = 100
|
|||||||
//
|
//
|
||||||
// The JSON spec itself does not define a limit, but allows implementations to
|
// The JSON spec itself does not define a limit, but allows implementations to
|
||||||
// set their own limits.
|
// set their own limits.
|
||||||
pri const DECODER_NUMBER_LENGTH_MAX_INCL : base.u64 = 99
|
pri const DECODER_NUMBER_LENGTH_MAX_INCL : base.u64 = 2047
|
||||||
|
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
|
|||||||
+44
-41
@@ -75,7 +75,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
|||||||
// https://github.com/google/wuffs/commit/86d3b89f9a6578d964a4b6d71e21dfc9bb702b44
|
// https://github.com/google/wuffs/commit/86d3b89f9a6578d964a4b6d71e21dfc9bb702b44
|
||||||
|
|
||||||
var vminor : base.u32[..= 0xFF_FFFF]
|
var vminor : base.u32[..= 0xFF_FFFF]
|
||||||
var number_length : base.u32[..= 0x3FF]
|
var number_length : base.u32[..= 0x3FFF]
|
||||||
var number_status : base.u32[..= 0x3]
|
var number_status : base.u32[..= 0x3]
|
||||||
var string_length : base.u32[..= 0xFFFB]
|
var string_length : base.u32[..= 0xFFFB]
|
||||||
var whitespace_length : base.u32[..= 0xFFFE]
|
var whitespace_length : base.u32[..= 0xFFFE]
|
||||||
@@ -905,17 +905,17 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
|||||||
pre args.dst.available() > 0,
|
pre args.dst.available() > 0,
|
||||||
{
|
{
|
||||||
number_length = this.decode_number!(src: args.src)
|
number_length = this.decode_number!(src: args.src)
|
||||||
number_status = number_length >> 8
|
number_status = number_length >> 12
|
||||||
vminor = (base.TOKEN__VBC__NUMBER << 21) |
|
vminor = (base.TOKEN__VBC__NUMBER << 21) |
|
||||||
base.TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |
|
base.TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |
|
||||||
base.TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED |
|
base.TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED |
|
||||||
base.TOKEN__VBD__NUMBER__FORMAT_TEXT
|
base.TOKEN__VBD__NUMBER__FORMAT_TEXT
|
||||||
if (number_length & 0x80) <> 0 {
|
if (number_length & 0x800) <> 0 {
|
||||||
vminor = (base.TOKEN__VBC__NUMBER << 21) |
|
vminor = (base.TOKEN__VBC__NUMBER << 21) |
|
||||||
base.TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |
|
base.TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |
|
||||||
base.TOKEN__VBD__NUMBER__FORMAT_TEXT
|
base.TOKEN__VBD__NUMBER__FORMAT_TEXT
|
||||||
}
|
}
|
||||||
number_length = number_length & 0x7F
|
number_length = number_length & 0x7FF
|
||||||
if number_status == 0 {
|
if number_status == 0 {
|
||||||
args.dst.write_simple_token_fast!(
|
args.dst.write_simple_token_fast!(
|
||||||
value_major: 0,
|
value_major: 0,
|
||||||
@@ -1196,10 +1196,10 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
|
|||||||
this.end_of_data = true
|
this.end_of_data = true
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FFF] {
|
||||||
var c : base.u8
|
var c : base.u8
|
||||||
var n : base.u32[..= 0x3FF]
|
var n : base.u32[..= 0x3FFF]
|
||||||
var floating_point : base.u32[..= 0x80]
|
var floating_point : base.u32[..= 0x800]
|
||||||
|
|
||||||
while.goto_done true {{
|
while.goto_done true {{
|
||||||
n = 0
|
n = 0
|
||||||
@@ -1207,7 +1207,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
|||||||
// Peek.
|
// Peek.
|
||||||
if args.src.available() <= 0 {
|
if args.src.available() <= 0 {
|
||||||
if not args.src.is_closed() {
|
if not args.src.is_closed() {
|
||||||
n |= 0x300
|
n |= 0x3000
|
||||||
}
|
}
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
@@ -1224,9 +1224,9 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
|||||||
// Peek.
|
// Peek.
|
||||||
if args.src.available() <= 0 {
|
if args.src.available() <= 0 {
|
||||||
if not args.src.is_closed() {
|
if not args.src.is_closed() {
|
||||||
n |= 0x300
|
n |= 0x3000
|
||||||
}
|
}
|
||||||
n |= 0x100 // A '-' without digits is invalid.
|
n |= 0x1000 // A '-' without digits is invalid.
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
c = args.src.peek_u8()
|
c = args.src.peek_u8()
|
||||||
@@ -1239,19 +1239,19 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
|||||||
if c == '0' {
|
if c == '0' {
|
||||||
n += 1
|
n += 1
|
||||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||||
assert n <= 99
|
assert n <= 2047
|
||||||
} else {
|
} else {
|
||||||
n = this.decode_digits!(src: args.src, n: n)
|
n = this.decode_digits!(src: args.src, n: n)
|
||||||
if n > 99 {
|
if n > 2047 {
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
assert n <= 99
|
assert n <= 2047
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peek.
|
// Peek.
|
||||||
if args.src.available() <= 0 {
|
if args.src.available() <= 0 {
|
||||||
if not args.src.is_closed() {
|
if not args.src.is_closed() {
|
||||||
n |= 0x300
|
n |= 0x3000
|
||||||
}
|
}
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
@@ -1260,68 +1260,68 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
|||||||
// Scan the optional fraction.
|
// Scan the optional fraction.
|
||||||
if c <> '.' {
|
if c <> '.' {
|
||||||
assert args.src.available() > 0
|
assert args.src.available() > 0
|
||||||
assert n <= 99
|
assert n <= 2047
|
||||||
} else {
|
} else {
|
||||||
if n >= 99 {
|
if n >= 2047 {
|
||||||
n |= 0x200
|
n |= 0x2000
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
n += 1
|
n += 1
|
||||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||||
floating_point = 0x80
|
floating_point = 0x800
|
||||||
|
|
||||||
n = this.decode_digits!(src: args.src, n: n)
|
n = this.decode_digits!(src: args.src, n: n)
|
||||||
if n > 99 {
|
if n > 2047 {
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peek.
|
// Peek.
|
||||||
if args.src.available() <= 0 {
|
if args.src.available() <= 0 {
|
||||||
if not args.src.is_closed() {
|
if not args.src.is_closed() {
|
||||||
n |= 0x300
|
n |= 0x3000
|
||||||
}
|
}
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
c = args.src.peek_u8()
|
c = args.src.peek_u8()
|
||||||
|
|
||||||
assert args.src.available() > 0
|
assert args.src.available() > 0
|
||||||
assert n <= 99
|
assert n <= 2047
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan the optional 'E' or 'e'.
|
// Scan the optional 'E' or 'e'.
|
||||||
if (c <> 'E') and (c <> 'e') {
|
if (c <> 'E') and (c <> 'e') {
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
if n >= 99 {
|
if n >= 2047 {
|
||||||
n |= 0x200
|
n |= 0x2000
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
n += 1
|
n += 1
|
||||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||||
floating_point = 0x80
|
floating_point = 0x800
|
||||||
assert n <= 99
|
assert n <= 2047
|
||||||
|
|
||||||
// Peek.
|
// Peek.
|
||||||
if args.src.available() <= 0 {
|
if args.src.available() <= 0 {
|
||||||
if not args.src.is_closed() {
|
if not args.src.is_closed() {
|
||||||
n |= 0x300
|
n |= 0x3000
|
||||||
}
|
}
|
||||||
n |= 0x100 // An 'E' or 'e' without digits is invalid.
|
n |= 0x1000 // An 'E' or 'e' without digits is invalid.
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
c = args.src.peek_u8()
|
c = args.src.peek_u8()
|
||||||
|
|
||||||
// Scan the optional '+' or '-'.
|
// Scan the optional '+' or '-'.
|
||||||
if (c <> '+') and (c <> '-') {
|
if (c <> '+') and (c <> '-') {
|
||||||
assert n <= 99
|
assert n <= 2047
|
||||||
} else {
|
} else {
|
||||||
if n >= 99 {
|
if n >= 2047 {
|
||||||
n |= 0x200
|
n |= 0x2000
|
||||||
break.goto_done
|
break.goto_done
|
||||||
}
|
}
|
||||||
n += 1
|
n += 1
|
||||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||||
assert n <= 99
|
assert n <= 2047
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan the exponent digits.
|
// Scan the exponent digits.
|
||||||
@@ -1333,15 +1333,15 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
|||||||
return n | floating_point
|
return n | floating_point
|
||||||
}
|
}
|
||||||
|
|
||||||
pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u32[..= 0x3FF] {
|
pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 2047]) base.u32[..= 0x3FFF] {
|
||||||
var c : base.u8
|
var c : base.u8
|
||||||
var n : base.u32[..= 0x3FF]
|
var n : base.u32[..= 0x3FFF]
|
||||||
|
|
||||||
n = args.n
|
n = args.n
|
||||||
while true {
|
while true {
|
||||||
if args.src.available() <= 0 {
|
if args.src.available() <= 0 {
|
||||||
if not args.src.is_closed() {
|
if not args.src.is_closed() {
|
||||||
n |= 0x300
|
n |= 0x3000
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -1349,24 +1349,27 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 99]) base.u
|
|||||||
if 0x00 == LUT_DECIMAL_DIGITS[c] {
|
if 0x00 == LUT_DECIMAL_DIGITS[c] {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Cap DECODER_NUMBER_LENGTH_MAX_INCL at an arbitrary value, 99. The
|
// Cap DECODER_NUMBER_LENGTH_MAX_INCL at an arbitrary value, 2047. The
|
||||||
// caller's src.data.len should therefore be at least 100, also known
|
// caller's src.data.len should therefore be at least 2048, also known
|
||||||
// as DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL.
|
// as DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL.
|
||||||
//
|
//
|
||||||
// An example of a JSON number that is 81 bytes long is:
|
// An example of a JSON number that is 81 bytes long is:
|
||||||
// https://github.com/nst/JSONTestSuite/blob/master/test_parsing/y_number_double_close_to_zero.json
|
// https://github.com/nst/JSONTestSuite/blob/master/test_parsing/y_number_double_close_to_zero.json
|
||||||
//
|
//
|
||||||
// Note that 99 (in hex, 0x63) is less than 0x80, so we can use 0x80 as
|
// A exact rendering (in printf's "%f" format) of 5e-324 can run to
|
||||||
// a flag bit in func decoder.decode_number.
|
// almost 1100 bytes.
|
||||||
if n >= 99 {
|
//
|
||||||
n |= 0x200
|
// Note that 2047 (in hex, 0x7FF) is less than 0x800, so we can use
|
||||||
|
// 0x800 as a flag bit in func decoder.decode_number.
|
||||||
|
if n >= 2047 {
|
||||||
|
n |= 0x2000
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
n += 1
|
n += 1
|
||||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||||
} endwhile
|
} endwhile
|
||||||
if n == args.n {
|
if n == args.n {
|
||||||
n |= 0x100
|
n |= 0x1000
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -1982,14 +1982,14 @@ test_wuffs_json_decode_long_numbers() {
|
|||||||
{.valid = true, .suffix = ".2e-5678 "},
|
{.valid = true, .suffix = ".2e-5678 "},
|
||||||
};
|
};
|
||||||
|
|
||||||
// src_array holds the overall test string. 119 is arbitrary but long enough.
|
// src_array holds the overall test string. 2090 is arbitrary but long
|
||||||
// See the "if (suffix_length > etc)" check below. 102 is also arbitrary but
|
// enough. See the "if (suffix_length > etc)" check below. 2060 is also
|
||||||
// larger than WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL.
|
// arbitrary but larger than WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL.
|
||||||
//
|
//
|
||||||
// See also test_wuffs_json_decode_src_io_buffer_length.
|
// See also test_wuffs_json_decode_src_io_buffer_length.
|
||||||
uint8_t src_array[119];
|
uint8_t src_array[2090];
|
||||||
memset(&src_array[0], '9', 102);
|
memset(&src_array[0], '9', 2060);
|
||||||
if (102 <= WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL) {
|
if (2060 <= WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL) {
|
||||||
RETURN_FAIL("insufficient number_length test case coverage");
|
RETURN_FAIL("insufficient number_length test case coverage");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1998,7 +1998,7 @@ test_wuffs_json_decode_long_numbers() {
|
|||||||
int tc;
|
int tc;
|
||||||
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||||
size_t suffix_length = strlen(test_cases[tc].suffix);
|
size_t suffix_length = strlen(test_cases[tc].suffix);
|
||||||
if ((suffix_length + 1) > (119 - 102)) { // +1 for the terminal NUL.
|
if ((suffix_length + 1) > (2090 - 2060)) { // +1 for the terminal NUL.
|
||||||
RETURN_FAIL("tc=%d: src_array is too short", tc);
|
RETURN_FAIL("tc=%d: src_array is too short", tc);
|
||||||
}
|
}
|
||||||
bool ends_with_space = (suffix_length > 0) &&
|
bool ends_with_space = (suffix_length > 0) &&
|
||||||
@@ -2007,12 +2007,12 @@ test_wuffs_json_decode_long_numbers() {
|
|||||||
// Copying the terminal NUL isn't necessary for Wuffs' slices (which are a
|
// Copying the terminal NUL isn't necessary for Wuffs' slices (which are a
|
||||||
// pointer-length pair), but this backstop can help debugging with printf
|
// pointer-length pair), but this backstop can help debugging with printf
|
||||||
// where "%s" takes a C string (a bare pointer).
|
// where "%s" takes a C string (a bare pointer).
|
||||||
memcpy(&src_array[102], test_cases[tc].suffix, suffix_length + 1);
|
memcpy(&src_array[2060], test_cases[tc].suffix, suffix_length + 1);
|
||||||
|
|
||||||
size_t nines_length;
|
size_t nines_length;
|
||||||
for (nines_length = 90; nines_length < 102; nines_length++) {
|
for (nines_length = 2037; nines_length < 2050; nines_length++) {
|
||||||
wuffs_base__slice_u8 src_data = ((wuffs_base__slice_u8){
|
wuffs_base__slice_u8 src_data = ((wuffs_base__slice_u8){
|
||||||
.ptr = &src_array[102 - nines_length],
|
.ptr = &src_array[2060 - nines_length],
|
||||||
.len = nines_length + suffix_length,
|
.len = nines_length + suffix_length,
|
||||||
});
|
});
|
||||||
size_t number_length = src_data.len - (ends_with_space ? 1 : 0);
|
size_t number_length = src_data.len - (ends_with_space ? 1 : 0);
|
||||||
@@ -3019,10 +3019,10 @@ test_wuffs_json_decode_src_io_buffer_length() {
|
|||||||
"WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL");
|
"WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL");
|
||||||
}
|
}
|
||||||
|
|
||||||
// src_array holds the test string of repeated '7's. 107 is arbitrary but
|
// src_array holds the test string of repeated '7's. 2050 is arbitrary but
|
||||||
// long enough for the loop below.
|
// long enough for the loop below.
|
||||||
uint8_t src_array[107];
|
uint8_t src_array[2050];
|
||||||
memset(&src_array[0], '7', 107);
|
memset(&src_array[0], '7', 2050);
|
||||||
|
|
||||||
wuffs_json__decoder dec;
|
wuffs_json__decoder dec;
|
||||||
|
|
||||||
@@ -3031,7 +3031,7 @@ test_wuffs_json_decode_src_io_buffer_length() {
|
|||||||
i <= WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL + 2; i++) {
|
i <= WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL + 2; i++) {
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
RETURN_FAIL("invalid test case: i=%d", i);
|
RETURN_FAIL("invalid test case: i=%d", i);
|
||||||
} else if (i > 107) {
|
} else if (i > 2050) {
|
||||||
RETURN_FAIL("invalid test case: i=%d", i);
|
RETURN_FAIL("invalid test case: i=%d", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user