From 83ae50ce9bc71e74fe36f4da64cab561934b2e73 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 24 Feb 2020 11:10:01 +1100 Subject: [PATCH] Raise std/json's max number length from 49 to 99 --- release/c/wuffs-unsupported-snapshot.c | 2 +- std/json/decode_json.wuffs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 2f8ec8a8..15ae7d6e 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -19367,7 +19367,7 @@ wuffs_json__decoder__decode_digits(wuffs_json__decoder* self, if ((v_c < 48) || (57 < v_c)) { goto label_0_break; } - if (v_n >= 49) { + if (v_n >= 99) { v_n |= 512; goto label_0_break; } diff --git a/std/json/decode_json.wuffs b/std/json/decode_json.wuffs index b6cd2455..40183db8 100644 --- a/std/json/decode_json.wuffs +++ b/std/json/decode_json.wuffs @@ -690,7 +690,15 @@ pri func decoder.decode_digits!(src: base.io_reader, n: base.u32[..= 0xFF]) base if (c < 0x30) or (0x39 < c) { break } - if n >= 49 { + // Cap the maximum supported number length at an arbitrary value, 99. + // The caller's src.data.len should therefore be at least 100. + // + // 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 + // + // Note that 99 (in hex, 0x63) is less than 0x80, so we can use 0x80 as + // a flag bit in func decoder.decode_number. + if n >= 99 { n |= 0x200 break }