shangxinli commented on code in PR #961:
URL: https://github.com/apache/iceberg-cpp/pull/961#discussion_r4271877874


##########
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);

Review Comment:
   Constructing a span of INT32_MAX + 1 elements over a one-byte object is 
itself UB ([span.cons] requires [ptr, ptr + count) to be a valid range), so the 
test is ill-formed even though it never dereferences. It also will not be 
caught by UBSan, since the constructor just stores the pointer and count.



-- 
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]

Reply via email to