Skip to content

GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members#50234

Merged
kou merged 3 commits into
apache:mainfrom
Reranko05:ruby-memory-view-init
Jun 24, 2026
Merged

GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members#50234
kou merged 3 commits into
apache:mainfrom
Reranko05:ruby-memory-view-init

Conversation

@Reranko05

@Reranko05 Reranko05 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

rb_memory_view_get() callers may pass a non-zero-initialized rb_memory_view_t. primitive_array_get() and buffer_get() did not initialize item_desc.components and item_desc.length, which could cause rb_memory_view_release() to attempt to free an invalid pointer and abort the process.

What changes are included in this PR?

This change initializes item_desc.components and item_desc.length in both primitive_array_get() and buffer_get().

It also adds regression tests that verify releasing a memory view with a non-zero-initialized rb_memory_view_t does not crash for both Arrow::Int32Array and Arrow::Buffer.

Are these changes tested?

Yes. Added regression tests in test-memory-view.rb that reproduced the crash before this change and pass after the fix.

Are there any user-facing changes?

No.

This PR contains a "Critical Fix".

This change fixes a crash that could occur when rb_memory_view_release() is called with a memory view whose item_desc members were not initialized.

@Reranko05 Reranko05 requested a review from kou as a code owner June 22, 2026 11:28
Copilot AI review requested due to automatic review settings June 22, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

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

@Reranko05

Copy link
Copy Markdown
Contributor Author

@kou The lint failure appears unrelated to this PR. It was caused by a ShellCheck Docker image pull issue. The same dev lint workflow passes successfully on my fork.

Comment thread ruby/red-arrow/ext/arrow/memory-view.cpp Outdated
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Jun 22, 2026
@Reranko05 Reranko05 force-pushed the ruby-memory-view-init branch from 19e6c5c to bd83fad Compare June 23, 2026 00:48
@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 23, 2026
@Reranko05

Copy link
Copy Markdown
Contributor Author

@kou Thanks for the review. Addressed all review comments.

  • Switched memory view initialization to memset(view_, 0, sizeof(memory_view)).
  • Added regression tests for uninitialized rb_memory_view_t handling under a dedicated sub_test_case.
  • Updated the Fiddle bindings to use TYPE_BOOL.
  • Used Fiddle::Pointer.malloc(..., Fiddle::RUBY_FREE) for automatic cleanup.
  • Replaced assert_nothing_raised with explicit return value checks.

@Reranko05

Copy link
Copy Markdown
Contributor Author

@kou One question about the regression tests: I added the sub_test_case structure you suggested, but I noticed your earlier comment about avoiding the hard-coded 256 size and possibly not adding tests for this case at all.

Would you prefer keeping the tests as they are now, or removing them entirely?

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefered not adding tests for this at all in the first review because I feel that we don't want to maintain these tests. But I'm OK with adding them now because they are organized now.

Comment thread ruby/red-arrow/ext/arrow/memory-view.cpp
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 23, 2026
Copilot AI review requested due to automatic review settings June 23, 2026 06:08
@Reranko05 Reranko05 force-pushed the ruby-memory-view-init branch from bd83fad to 1c5ad91 Compare June 23, 2026 06:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 23, 2026
@Reranko05

Copy link
Copy Markdown
Contributor Author

I prefered not adding tests for this at all in the first review because I feel that we don't want to maintain these tests. But I'm OK with adding them now because they are organized now.

@kou Thanks for the clarification.

Comment thread ruby/red-arrow/test/test-memory-view.rb Outdated
Copilot AI review requested due to automatic review settings June 23, 2026 06:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread ruby/red-arrow/ext/arrow/memory-view.cpp Outdated
Copilot AI review requested due to automatic review settings June 23, 2026 06:18
@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@github-actions github-actions Bot added awaiting change review Awaiting change review awaiting merge Awaiting merge and removed awaiting changes Awaiting changes awaiting change review Awaiting change review labels Jun 23, 2026
@Reranko05

Copy link
Copy Markdown
Contributor Author

@kou Thanks for the review. All CI checks have completed successfully now.

@kou kou merged commit 12b3eda into apache:main Jun 24, 2026
16 of 17 checks passed
@kou kou removed the awaiting merge Awaiting merge label Jun 24, 2026
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 12b3eda.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 8 possible false positives for unstable benchmarks that are known to sometimes produce them.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants