Skip to content

Commit b4623cb

Browse files
authored
Merge pull request #1 from falbrechtskirchinger/issue3541
add test cases to 32bit unit test
2 parents 0f8a59f + 2d5fa1c commit b4623cb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/src/unit-32bit.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,30 @@ TEST_CASE("BJData")
9898
{
9999
SECTION("array")
100100
{
101+
SECTION("optimized array: negative size")
102+
{
103+
std::vector<uint8_t> vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'};
104+
std::vector<uint8_t> vMX = {'[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']'};
105+
106+
json _;
107+
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
108+
CHECK(json::from_bjdata(vM, true, false).is_discarded());
109+
110+
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vMX), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
111+
CHECK(json::from_bjdata(vMX, true, false).is_discarded());
112+
}
113+
101114
SECTION("optimized array: integer value overflow")
102115
{
103116
std::vector<uint8_t> vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F};
104117
std::vector<uint8_t> vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'};
105118

106119
json _;
107120
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
121+
CHECK(json::from_bjdata(vL, true, false).is_discarded());
108122

109123
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
124+
CHECK(json::from_bjdata(vM, true, false).is_discarded());
110125
}
111126
}
112127
}

tests/src/unit-bjdata.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,10 +2673,12 @@ TEST_CASE("BJData")
26732673
json _;
26742674
#if SIZE_MAX == 0xffffffff
26752675
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
2676+
CHECK(json::from_bjdata(vL, true, false).is_discarded());
26762677
#endif
26772678

26782679
#if SIZE_MAX == 0xffffffff
26792680
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
2681+
CHECK(json::from_bjdata(vM, true, false).is_discarded());
26802682
#endif
26812683
}
26822684

0 commit comments

Comments
 (0)