Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#52,021 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
101

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/arrow のほかの issue

apache/arrow の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。