fix: reject JSON integers outside the u64/i64 range instead of rounding them (#10481)

* test: reject JSON integers outside the u64/i64 range

Signed-off-by: dayan02dev <pawarudayan92@gmail.com>

* fix: bump jsonb to reject integers outside the u64/i64 range

Signed-off-by: dayan02dev <pawarudayan92@gmail.com>

---------

Signed-off-by: dayan02dev <pawarudayan92@gmail.com>
This commit is contained in:
dayan02dev
2026-11-23 20:19:08 +00:00
committed by GitHub
parent b26b87f914
commit f15fd9a706
5 changed files with 29 additions and 2 deletions
Generated
+1 -1
View File
@@ -7622,7 +7622,7 @@ dependencies = [
[[package]]
name = "jsonb"
version = "0.5.6"
source = "git+https://github.com/GreptimeTeam/jsonb?rev=5a6472858d860ac034075c17253f41617bdfa956#5a6472858d860ac034075c17253f41617bdfa956"
source = "git+https://github.com/GreptimeTeam/jsonb?rev=ae1ca9a26c65902dac9b53864bf502843c312ea5#ae1ca9a26c65902dac9b53864bf502843c312ea5"
dependencies = [
"byteorder",
"ethnum",
+1 -1
View File
@@ -177,7 +177,7 @@ icu_properties = "2.0.1"
indicatif = "0.17"
intern-arc = "0.6.2"
itertools = "0.14"
jsonb = { git = "https://github.com/GreptimeTeam/jsonb", rev = "5a6472858d860ac034075c17253f41617bdfa956", default-features = false, features = [
jsonb = { git = "https://github.com/GreptimeTeam/jsonb", rev = "ae1ca9a26c65902dac9b53864bf502843c312ea5", default-features = false, features = [
"databend",
] }
lazy_static = "1.4"
+15
View File
@@ -442,6 +442,21 @@ mod tests {
}
}
#[test]
fn test_parse_json_rejects_integers_out_of_range() {
for input in [
"18446744073709551616",
"-9223372036854775809",
r#"{"n": 123456789012345678901234567890}"#,
] {
assert!(parse_string_to_jsonb(input).is_err(), "{input}");
}
for input in ["18446744073709551615", "-9223372036854775808"] {
let jsonb = parse_string_to_jsonb(input).unwrap();
assert_eq!(jsonb_to_string(&jsonb).unwrap(), input);
}
}
#[test]
fn test_v2_jsonb_to_serde_json_escaped_keys()
-> std::result::Result<(), Box<dyn std::error::Error>> {
@@ -129,6 +129,14 @@ INSERT INTO jsons VALUES(parse_json('Morning my friends, have a nice day :)'), 5
Error: 3001(EngineExecuteQuery), Execution error: cannot parse 'Morning my friends, have a nice day :)': expected value, pos 1
INSERT INTO jsons VALUES(parse_json('{"n": 18446744073709551616}'), 6);
Error: 3001(EngineExecuteQuery), Execution error: cannot parse '{"n": 18446744073709551616}': invalid number, pos 26
INSERT INTO jsons VALUES('{"n": -9223372036854775809}', 7);
Error: 1004(InvalidArguments), Invalid JSON: {"n": -9223372036854775809}
SELECT json_to_string(j), t FROM jsons;
+-------------------------+---+
@@ -85,6 +85,10 @@ INSERT INTO jsons VALUES(parse_json('{"a":1, "b":2, "c":3'), 4);
INSERT INTO jsons VALUES(parse_json('Morning my friends, have a nice day :)'), 5);
INSERT INTO jsons VALUES(parse_json('{"n": 18446744073709551616}'), 6);
INSERT INTO jsons VALUES('{"n": -9223372036854775809}', 7);
SELECT json_to_string(j), t FROM jsons;
CREATE TABLE json_empty (j JSON, t timestamp time index);