Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Ruby] Wrong data pointer in MemoryView of a sliced array

未关闭 适合新手
#52,021 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@gitedmond 已经在做这个了。

开始于 2026年10月7日。

  • #52286 来自 @gitedmond —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp, ruby
领域
data

调研方向

从 ext/arrow/memory-view.cpp 中的 PrimitiveArrayGetter::fill 开始,GetValuesSafe<uint8_t>(1) 在这里以字节而非元素单位应用数组偏移。用 issue 中的代码片段(对一个 Arrow::Int32Array 进行切片,再通过 Fiddle::MemoryView 读回)复现问题,然后按固定宽度元素大小缩放偏移(如 issue 中建议的代码片段所示),使 data、item_size 和 byte_size 保持一致。当多字节基本类型数组的切片能解包出预期值时即告完成;查看 ext/arrow 的测试套件,找到可扩展的现有 memory-view 测试。

由索引模型根据 Issue 内容生成。

描述

Component: Ruby Type: bug
Describe the bug, including details regarding any error messages, version, and platform.

For a sliced primitive array, the data pointer of the exported
MemoryView is advanced by offset bytes instead of
offset × element size bytes, so values wider than one byte come
out wrong (no error is raised).

require "arrow"
require "fiddle"

a = Arrow::Int32Array.new([0, 1, 2, 3, 4, 5, 6, 7])
p Fiddle::MemoryView.new(a.slice(1, 3)).to_s.unpack("l*")
# => [16777216, 33554432, 50331648]   expected [1, 2, 3]
p Fiddle::MemoryView.new(a.slice(4, 3)).to_s.unpack("l*")
# => [1, 2, 3]                         expected [4, 5, 6]

The cause is GetValuesSafe<uint8_t>(1) in PrimitiveArrayGetter::fill
(ext/arrow/memory-view.cpp): it adds the offset in units of uint8_t.
The offset should be scaled by the element width.

A possible fix is to take the buffer start and scale the offset by the
element width:

const auto type =
  std::static_pointer_cast<const arrow::FixedWidthType>(array.type());
view_->item_size = type->bit_width() / 8;
const auto base = array_data->GetValuesSafe<uint8_t>(1, 0);
const auto data = base + array_data->offset * view_->item_size;
view_->data = const_cast<void *>(reinterpret_cast<const void *>(data));
view_->byte_size = view_->item_size * array.length();

red-arrow 25.0.1, Ruby 3.4.1, macOS (arm64).

Component(s)

Ruby

主要语言
C++
星标
17.2k
派生
4.3k
平均合并
4 天 5 小时
30 天内合并 PR
101

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/arrow 的其他 Issue

查看 apache/arrow 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。