Skip to content

Commit d463bfb

Browse files
committed
test: serde validation cases
1 parent 2c712e9 commit d463bfb

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

tuple/include/array_of_strings_sketch_impl.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ uint32_t default_array_of_strings_serde<Allocator>::compute_total_bytes(const ar
240240
for (uint32_t j = 0; j < count; ++j) {
241241
total += data[j].size();
242242
}
243-
if (total > std::numeric_limits<uint32_t>::max()) {
244-
throw std::runtime_error("array_of_strings serialized size exceeds uint32_t max");
245-
}
246243
return static_cast<uint32_t>(total);
247244
}
248245

tuple/test/array_of_strings_sketch_test.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,30 @@ TEST_CASE("aos sketch: serialize deserialize", "[tuple_sketch]") {
255255
}
256256
}
257257

258+
TEST_CASE("aos serde validation", "[tuple_sketch]") {
259+
default_array_of_strings_serde<> serde;
260+
261+
SECTION("invalid utf8 rejected") {
262+
array_of_strings array(1, "", std::allocator<std::string>());
263+
const std::string invalid_utf8("\xC3\x28", 2);
264+
array[0] = invalid_utf8;
265+
std::stringstream ss;
266+
ss.exceptions(std::ios::failbit | std::ios::badbit);
267+
REQUIRE_THROWS_WITH(
268+
serde.serialize(ss, &array, 1),
269+
Catch::Matchers::Contains("invalid UTF-8")
270+
);
271+
}
272+
273+
SECTION("too many nodes rejected") {
274+
array_of_strings array(128, "", std::allocator<std::string>());
275+
std::stringstream ss;
276+
ss.exceptions(std::ios::failbit | std::ios::badbit);
277+
REQUIRE_THROWS_WITH(
278+
serde.serialize(ss, &array, 1),
279+
Catch::Matchers::Contains("size exceeds 127")
280+
);
281+
}
282+
}
283+
258284
} /* namespace datasketches */

0 commit comments

Comments
 (0)