Skip to content

MINOR: [C++] Prevent null pointer arithmetic in Buffer and MutableBuffer slicing - #55439

Open
atharva-potdar wants to merge 2 commits into
apache:mainfrom
atharva-potdar:fix-buffer-null-slice
Open

atharva-potdar wants to merge 2 commits into
apache:mainfrom
atharva-potdar:fix-buffer-null-slice

Conversation

@atharva-potdar

@atharva-potdar atharva-potdar commented Nov 7, 2026 •

Copy link
Copy Markdown

Rationale for this change

Currently, the slicing constructors for Buffer (src/arrow/buffer.h) and MutableBuffer (src/arrow/buffer.cc) unconditionally add offset to the parent buffer's pointer/address. When slicing a null-backed buffer where parent->data_ is nullptr or parent->mutable_address() is 0 with a non-zero offset, this performs undefined pointer arithmetic on a null pointer (producing a corrupt non-null address 0x0 + offset) and triggers clang-analyzer-core.NullPointerArithm in clang-tidy:

src/arrow/buffer.cc:167:75: warning: Addition of a null pointer and a nonzero integer value (from variable 'offset') results in undefined behavior [clang-analyzer-core.NullPointerArithm]

What changes are included in this PR?

  • Guard Buffer's slice constructor in src/arrow/buffer.h against null parent->data_ before adding offset.
  • Guard MutableBuffer's slice constructor in src/arrow/buffer.cc using parent->mutable_address() (preserving non-CPU device compatibility from ARROW-2447) and performing integer addition before casting when non-zero.
  • Add TestBuffer.SliceNullBuffer in src/arrow/buffer_test.cc.

Are these changes tested?

Yes, added TestBuffer.SliceNullBuffer in arrow-buffer-test (which fails on unpatched main where sliced->data() evaluates to 0x8 instead of nullptr, and passes with this fix) and verified that clang-tidy no longer emits clang-analyzer-core.NullPointerArithm.

Are there any user-facing changes?

No.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code written by:

  • Human
  • AI

PR description written by:

  • Human
  • AI

I asked Gemini 4 Argon to write a PR description after I wrote the test, the code, and pasted the clang-tidy and google test logs to it.

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI balanced review requested due to automatic review settings November 7, 2026 07:38

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 insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 7, 2026 07:57

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 insufficient remaining quota. Try requesting a review at a lower effort level.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants