You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/09/08 15:54:30 UTC

[GitHub] [arrow] bkietz commented on a change in pull request #8126: ARROW-9931: [C++] Fix undefined behaviour on invalid IPC input

bkietz commented on a change in pull request #8126:
URL: https://github.com/apache/arrow/pull/8126#discussion_r485025998



##########
File path: cpp/src/arrow/buffer.cc
##########
@@ -277,13 +277,18 @@ Result<std::unique_ptr<ResizableBuffer>> AllocateResizableBuffer(const int64_t s
 }
 
 Result<std::shared_ptr<Buffer>> AllocateBitmap(int64_t length, MemoryPool* pool) {
-  return AllocateBuffer(BitUtil::BytesForBits(length), pool);
+  ARROW_ASSIGN_OR_RAISE(auto buf, AllocateBuffer(BitUtil::BytesForBits(length), pool));
+  // Zero out any trailing bits
+  if (buf->size() > 0) {
+    buf->mutable_data()[buf->size() - 1] = 0;
+  }
+  return std::move(buf);
 }
 
 Result<std::shared_ptr<Buffer>> AllocateEmptyBitmap(int64_t length, MemoryPool* pool) {
-  ARROW_ASSIGN_OR_RAISE(auto buf, AllocateBitmap(length, pool));
+  ARROW_ASSIGN_OR_RAISE(auto buf, AllocateBuffer(BitUtil::BytesForBits(length), pool));

Review comment:
       It's probably not worth changing that; `AllocateBuffer` zeroes the padding so this doesn't avoid touching the final cache line of this buffer




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org