[Ruby] Wrong data pointer in MemoryView of a sliced array
维护者通常 1 天内回复
评估
调研方向
从 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 内容生成。
描述
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
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/arrow 的其他 Issue
-
[C++][Python] IPC reader rejects a DictionaryEncoding without indexType, which the format allows可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭Component: C++ Component: Python
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
[R] Silent loss of metadata integrity for date-time and numeric attributes in write_parquet()/read_parquet()可能已有人在做 @james-finn-travers 于 5 天前认领。 未关闭Component: R Type: bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
[C++][Parquet] Plaintext-footer files written with AES_GCM_CTR_V1 record AES_GCM_V1 as the encryption algorithm and cannot be read可能已有人在做 @YusefSyed 于 5 天前认领。 未关闭Type: bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
[R] Expose ignore_extra_columns and pad_short_rows CSV parse options可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭Component: R good-first-issue Type: enhancement
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Component: C++
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
EsotericSoftware/spine-runtimes#3186 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Round video messages start gray and blocky with libx264: encoder is configured for 1,000,000 fps未关闭
难度 2/5 1-3 小时 新手友好度 78/100
telegramdesktop/tdesktop#31422 ·
维护者通常 9 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 5 天内回复