Skip to content

GH-49917: [Python] numpy_convert.cc memory management(Use-After-Free) Bugs for PyList_SetItem in SparseCSFTensorToNdarray#49916

Open
wr-web wants to merge 2 commits intoapache:mainfrom
wr-web:main
Open

GH-49917: [Python] numpy_convert.cc memory management(Use-After-Free) Bugs for PyList_SetItem in SparseCSFTensorToNdarray#49916
wr-web wants to merge 2 commits intoapache:mainfrom
wr-web:main

Conversation

@wr-web
Copy link
Copy Markdown

@wr-web wr-web commented May 5, 2026

Rationale for this change

Py_DECREF(item) in PyList_SetItem will cause Use-After-Free bug if PyList_SetItem(indptr.obj(), i, item) < 0 is true, cause PyList_SetItem always steals a reference to the item, even when it fails.

What changes are included in this PR?

  1. Remove Py_DECREF(item) in PyList_SetItem error path.

Are these changes tested?

By CI.

Are there any user-facing changes?

No.

wr-web added 2 commits May 5, 2026 13:05
Remove  incorrect reference count decrement for item.

apache#49915
Remove unnecessary reference count decrement for item.

apache#49915
@wr-web wr-web requested review from AlenkaF, raulcd and rok as code owners May 5, 2026 05:07
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

Copy link
Copy Markdown
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Can you use the PR description template instead of removing it?
Can you also use the expected title for the PR as described on the automated message?

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels May 6, 2026
@pitrou
Copy link
Copy Markdown
Member

pitrou commented May 6, 2026

(PR contents look good otherwise: PyList_SetItem always steals a reference to the item, even when it fails)

@wr-web wr-web changed the title Fix memory management in numpy_convert.cc [Python] GH-49915: [numpy_convert] memory management(Use-After-Free) Bugs for PyList_SetItem in SparseCSFTensorToNdarray May 6, 2026
@wr-web
Copy link
Copy Markdown
Author

wr-web commented May 6, 2026

Thanks for the PR. Can you use the PR description template instead of removing it? Can you also use the expected title for the PR as described on the automated message?

Done

@raulcd raulcd changed the title [Python] GH-49915: [numpy_convert] memory management(Use-After-Free) Bugs for PyList_SetItem in SparseCSFTensorToNdarray GH-49915: [Python] numpy_convert.cc memory management(Use-After-Free) Bugs for PyList_SetItem in SparseCSFTensorToNdarray May 6, 2026
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@raulcd raulcd changed the title GH-49915: [Python] numpy_convert.cc memory management(Use-After-Free) Bugs for PyList_SetItem in SparseCSFTensorToNdarray GH-49917: [Python] numpy_convert.cc memory management(Use-After-Free) Bugs for PyList_SetItem in SparseCSFTensorToNdarray May 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

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

@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting changes Awaiting changes labels May 6, 2026
Copy link
Copy Markdown
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

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

Thank you very much for the PR!
I've done a minor update to the title so our automated tools don't trip.

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.

4 participants