Copilot commented on code in PR #961:
URL: https://github.com/apache/iceberg-cpp/pull/961#discussion_r4092213325
##########
src/iceberg/test/bucket_util_test.cc:
##########
@@ -108,6 +112,20 @@ TEST(BucketUtilsTest, HashHelper) {
EXPECT_EQ(BucketUtils::HashBytes(fixed), -188683207);
}
+TEST(BucketUtilsTest, HashBytesRejectsOversizedInput) {
+ // Lengths above INT32_MAX would wrap the 32-bit signed length parameter of
+ // MurmurHash3_x86_32 and read out of bounds. Fabricate an oversized span
+ // (never dereferenced: HashBytes must reject it before touching the data)
+ // to avoid allocating 2 GiB in the test.
+ const uint8_t byte = 0;
+ const auto oversized_length =
+ static_cast<size_t>(std::numeric_limits<int32_t>::max()) + 1;
+ std::span<const uint8_t> oversized(&byte, oversized_length);
+ ASSERT_THAT([&]() { BucketUtils::HashBytes(oversized); },
Review Comment:
`std::span<const uint8_t> oversized(&byte, oversized_length);` violates
`std::span(pointer, count)`'s precondition (the pointer must refer to a
contiguous sequence of at least `count` elements). Even if `HashBytes` rejects
before dereferencing, constructing this span itself is undefined behavior and
can trip sanitizers or toolchains with hardening.
Consider changing the production API (or adding an internal overload) to
accept `(const uint8_t* data, size_t len)` so the test can pass `nullptr` + an
oversized `len` without forming an invalid span; then keep the span overload as
a thin wrapper for normal callers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]