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



##########
File path: cpp/src/arrow/compute/exec/util.h
##########
@@ -93,19 +93,27 @@ class TempVectorStack {
   }
   void alloc(uint32_t num_bytes, uint8_t** data, int* id) {
     int64_t old_top = top_;
-    top_ += PaddedAllocationSize(num_bytes);
+    top_ += PaddedAllocationSize(num_bytes) + 2 * sizeof(uint64_t);
     // Stack overflow check
     ARROW_DCHECK(top_ <= buffer_size_);
-    *data = buffer_->mutable_data() + old_top;
+    *data = buffer_->mutable_data() + old_top + sizeof(uint64_t);

Review comment:
       ```suggestion
       *data = buffer_->mutable_data() + old_top + sizeof(uint64_t);
       // We set 8 bytes before the beginning of the allocated range and
       // 8 bytes after the end to check for stack overflow (which would
       // result in those known bytes being corrupted).
   ```

##########
File path: cpp/src/arrow/compute/exec/util.h
##########
@@ -93,19 +93,27 @@ class TempVectorStack {
   }
   void alloc(uint32_t num_bytes, uint8_t** data, int* id) {
     int64_t old_top = top_;
-    top_ += PaddedAllocationSize(num_bytes);
+    top_ += PaddedAllocationSize(num_bytes) + 2 * sizeof(uint64_t);
     // Stack overflow check
     ARROW_DCHECK(top_ <= buffer_size_);
-    *data = buffer_->mutable_data() + old_top;
+    *data = buffer_->mutable_data() + old_top + sizeof(uint64_t);
+    reinterpret_cast<uint64_t*>(buffer_->mutable_data() + old_top)[0] = 
guard1_;
+    reinterpret_cast<uint64_t*>(buffer_->mutable_data() + top_)[-1] = guard2_;
     *id = num_vectors_++;
   }
   void release(int id, uint32_t num_bytes) {
     ARROW_DCHECK(num_vectors_ == id + 1);
-    int64_t size = PaddedAllocationSize(num_bytes);
+    int64_t size = PaddedAllocationSize(num_bytes) + 2 * sizeof(uint64_t);
+    ARROW_DCHECK(reinterpret_cast<const uint64_t*>(buffer_->mutable_data() + 
top_)[-1] ==
+                 guard2_);
     ARROW_DCHECK(top_ >= size);
     top_ -= size;
+    ARROW_DCHECK(reinterpret_cast<const uint64_t*>(buffer_->mutable_data() + 
top_)[0] ==
+                 guard1_);
     --num_vectors_;
   }
+  static constexpr uint64_t guard1_ = 0x3141592653589793ULL;

Review comment:
       Nit: the style guide dictates these should be named like `kGuard1, 
kGuard2, kPadding`
   ```suggestion
     static constexpr uint64_t guard1_ = 0x3141592653589793ULL;
   ```




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


Reply via email to