mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +00:00
AK: Do not coerce i64 and u64 values to i32 and u32
First, this isn't actually helpful, as we no longer store 32-bit values in JsonValue. They are stored as 64-bit values anyways. But more imporatantly, there was a bug here when trying to coerce an i64 to an i32. All negative values were cast to an i32, without checking if the value is below NumericLimits<i32>::min.
This commit is contained in:
parent
749cf2d1b5
commit
7b3b608caf
Notes:
github-actions[bot]
2024-09-27 08:48:15 +00:00
Author: https://github.com/trflynn89
Commit: 7b3b608caf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1546
Reviewed-by: https://github.com/tcl3 ✅
2 changed files with 32 additions and 13 deletions
|
@ -128,6 +128,34 @@ TEST_CASE(json_64_bit_value)
|
|||
EXPECT(big_json_value.equals(big_json_value_copy));
|
||||
}
|
||||
|
||||
TEST_CASE(json_64_bit_value_coerced_to_32_bit)
|
||||
{
|
||||
{
|
||||
auto min = NumericLimits<i64>::min();
|
||||
auto max = NumericLimits<i64>::max();
|
||||
|
||||
auto json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(min))));
|
||||
EXPECT_EQ(json.get_integer<i64>(), min);
|
||||
EXPECT(!json.is_integer<i32>());
|
||||
|
||||
json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(max))));
|
||||
EXPECT_EQ(json.get_integer<i64>(), max);
|
||||
EXPECT(!json.is_integer<i32>());
|
||||
}
|
||||
{
|
||||
auto min = NumericLimits<u64>::min();
|
||||
auto max = NumericLimits<u64>::max();
|
||||
|
||||
auto json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(min))));
|
||||
EXPECT_EQ(json.get_integer<u64>(), min);
|
||||
EXPECT_EQ(json.get_integer<u32>(), min);
|
||||
|
||||
json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(max))));
|
||||
EXPECT_EQ(json.get_integer<u64>(), max);
|
||||
EXPECT(!json.is_integer<u32>());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(json_duplicate_keys)
|
||||
{
|
||||
JsonObject json;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue