Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] NumericArray<T> may not initialize values_ when construct #44541

Closed
mapleFU opened this issue Oct 28, 2024 · 1 comment
Closed

[C++] NumericArray<T> may not initialize values_ when construct #44541

mapleFU opened this issue Oct 28, 2024 · 1 comment
Assignees
Labels
Component: C++ Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. Type: bug
Milestone

Comments

@mapleFU
Copy link
Member

mapleFU commented Oct 28, 2024

Describe the bug, including details regarding any error messages, version, and platform.

The problem raised from [1]. NumericArray<T> uses values_ as a cache of typed values[2]. This might not being set when calling the PrimitiveArray::PrimitiveArray constructor [3]. The code can be reproduced like:

TEST(TestPrettyPrintArray, TimestampArray) {
  auto array = std::make_shared<TimestampArray>(
      timestamp(TimeUnit::MICRO),
      /*length=*/1, Buffer::FromVector(std::vector<int64_t>{0}));
  auto v0 = array->GetView(0);
  std::cout << v0 << std::endl;
}

This might be fixed with:

diff --git a/cpp/src/arrow/array/array_primitive.h b/cpp/src/arrow/array/array_primitive.h
index 3e2893b7dd..410e8516da 100644
--- a/cpp/src/arrow/array/array_primitive.h
+++ b/cpp/src/arrow/array/array_primitive.h
@@ -103,6 +103,15 @@ class NumericArray : public PrimitiveArray {
                             null_count, offset));
   }
 
+  NumericArray(const std::shared_ptr<DataType>& type, int64_t length,
+                 const std::shared_ptr<Buffer>& data,
+                 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
+                 int64_t null_count = kUnknownNullCount, int64_t offset = 0): PrimitiveArray(type, length, data, null_bitmap, null_count, offset) {
+      values_ = raw_values_
+                    ? (reinterpret_cast<const value_type*>(raw_values_) + data_->offset)
+                    : NULLPTR;
+  }
+
   const value_type* raw_values() const { return values_; }
 
   value_type Value(int64_t i) const { return values_[i]; }

But I don't know would I missed something.

[1] #44190
[2]

const value_type* values_;

[3]
using PrimitiveArray::PrimitiveArray;

Component(s)

C++

@mapleFU mapleFU added Type: bug Priority: Blocker Marks a blocker for the release labels Oct 28, 2024
@mapleFU mapleFU added this to the 18.0.0 milestone Oct 28, 2024
@mapleFU mapleFU removed this from the 18.0.0 milestone Oct 28, 2024
@mapleFU mapleFU removed the Priority: Blocker Marks a blocker for the release label Oct 28, 2024
mapleFU added a commit that referenced this issue Nov 11, 2024
…tly (#44542)

### Rationale for this change

See #44541

### What changes are included in this PR?

`NumericArray<T>` not using child's ctor.

### Are these changes tested?

Yes

### Are there any user-facing changes?

Bugfix

* GitHub Issue: #44541

Authored-by: mwish <[email protected]>
Signed-off-by: mwish <[email protected]>
@mapleFU mapleFU added this to the 19.0.0 milestone Nov 11, 2024
@mapleFU
Copy link
Member Author

mapleFU commented Nov 11, 2024

Issue resolved by pull request 44542
#44542

@mapleFU mapleFU closed this as completed Nov 11, 2024
@amoeba amoeba added the Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: C++ Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. Type: bug
Projects
None yet
Development

No branches or pull requests

2 participants