SteNicholas commented on code in PR #514:
URL: https://github.com/apache/paimon-cpp/pull/514#discussion_r4476256115
##########
src/paimon/common/memory/memory_slice_test.cpp:
##########
@@ -275,6 +275,20 @@ TEST_F(MemorySliceTest, TestSliceCopyBytes) {
ASSERT_NE(bytes->data(), copied->data());
}
+TEST_F(MemorySliceTest, TestSliceCopyEmptyBytes) {
+ auto bytes = std::make_shared<Bytes>(0, pool_.get());
+ MemorySlice slice = MemorySlice::Wrap(bytes);
+ auto copied = slice.CopyBytes(pool_.get());
+ ASSERT_TRUE(copied);
+ ASSERT_EQ(0u, copied->size());
Review Comment:
Please make the sanitizer regression checks fail when UBSan detects the
original bug. These assertions also pass with the old implementation. I ran all
four new tests against the base implementation in a macOS control build with
explicit nonnull annotations on memcpy. UBSan reported the null arguments at
all four copy sites, yet GoogleTest reported 4 passed and the process exited
with 0. With UBSAN_OPTIONS=halt_on_error=1, the corresponding base tests failed
and the PR version passed all four tests. The current build_support/run-test.sh
enables stack traces and suppressions, but leaves these UBSan reports
recoverable. Please run the focused tests with halt_on_error=1 in the Linux
sanitizer job, or use an equivalent fatal check, and verify that reverting the
guards makes that check fail.
##########
src/paimon/common/io/byte_array_input_stream_test.cpp:
##########
@@ -81,4 +81,53 @@ TEST(ByteArrayInputStreamTest, TestSimple) {
ASSERT_OK(input_stream->Close());
}
+TEST(ByteArrayInputStreamTest, TestZeroLengthRead) {
+ auto pool = GetDefaultPool();
+ Bytes empty_bytes(0, pool.get());
+ ByteArrayInputStream input_stream("abc", 3);
+ ASSERT_OK(input_stream.Seek(1, SeekOrigin::FS_SEEK_SET));
+
+ ASSERT_OK_AND_ASSIGN(int64_t read_size,
input_stream.Read(empty_bytes.data(), 0));
+ ASSERT_EQ(0, read_size);
+ ASSERT_OK_AND_ASSIGN(int64_t position, input_stream.GetPos());
+ ASSERT_EQ(1, position);
+
+ ASSERT_OK_AND_ASSIGN(read_size, input_stream.Read(empty_bytes.data(), 0,
/*offset=*/0));
+ ASSERT_EQ(0, read_size);
+ ASSERT_OK_AND_ASSIGN(read_size, input_stream.Read(empty_bytes.data(), 0,
/*offset=*/3));
+ ASSERT_EQ(0, read_size);
+ ASSERT_OK_AND_ASSIGN(position, input_stream.GetPos());
+ ASSERT_EQ(1, position);
+
+ bool read_finished = false;
+ input_stream.ReadAsync(empty_bytes.data(), 0, /*offset=*/3, [&](Status
status) {
+ ASSERT_OK(status);
+ read_finished = true;
+ });
+ ASSERT_TRUE(read_finished);
Review Comment:
Consider waiting for the callback result through a promise/future before
checking the status and stream position. This test currently passes because
ByteArrayInputStream invokes its callback synchronously. InputStream::ReadAsync
only promises a callback on completion, so a later implementation that
dispatches the callback would make the immediate read_finished assertion fail
and could access the captured local after the test returns. Synchronizing
completion would let the test verify successful zero-length reads and position
preservation without relying on inline callback execution.
--
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]