Skip to content

GH-54688: [Ruby] Keep buffer data alive after Ruby wrappers are collected - #55303

Open
GeorgiaPreda wants to merge 1 commit into
apache:mainfrom
GeorgiaPreda:fix/ruby-buffer-gc-lifetime
Open

GeorgiaPreda wants to merge 1 commit into
apache:mainfrom
GeorgiaPreda:fix/ruby-buffer-gc-lifetime

Conversation

@GeorgiaPreda

@GeorgiaPreda GeorgiaPreda commented Oct 28, 2026 •

Copy link
Copy Markdown

Rationale for this change

Fixes #54688. A Ruby buffer’s input can be garbage-collected while an array still references its native storage, causing subsequent reads to return corrupted values.

What changes are included in this PR?

  • Copy String and GLib::Bytes inputs into native-owned Arrow buffer storage.
  • Remove the redundant Ruby constructor-argument GC guard for Buffer.
  • Add regression tests covering garbage collection with chunked arrays and slices, and mutation of the original String.

Are these changes tested?

The corruption was reproduced before the fix. After the fix:

  • 1,800 selected Ruby tests passed.
  • 36 GLib buffer and stream tests passed.
  • RuboCop, Ruby syntax checks, and git diff --check passed.

Are there any user-facing changes?

Buffer contents remain valid when arrays outlive their Ruby wrappers. Constructing a buffer from a String or GLib::Bytes now copies the data into native-owned storage. Subsequent mutations to the original String no longer change the buffer’s contents.

This PR contains a "Critical Fix". It prevents corrupted array values caused by accessing input storage after Ruby garbage collection.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copy String and GLib::Bytes inputs into native-owned Arrow buffers.
Remove the redundant Ruby input guard and add array and slice GC regressions.

Fixes apache#54688
@GeorgiaPreda
GeorgiaPreda requested a review from kou as a code owner October 28, 2026 18:57
@github-actions github-actions Bot added the awaiting review Awaiting review label Oct 28, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #54688 has been automatically assigned in GitHub to PR creator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Awaiting review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Ruby] Memory passed to Arrow::Buffer.new is freed by GC while an array still refers to it

1 participant