Skip to content

gh-134070: Prevent out-of-bounds read in mi_clz32 and mi_ctz32 - #134149

Open
vedant713 wants to merge 8 commits into
python:mainfrom
vedant713:fix-mimalloc-bug
Open

gh-134070: Prevent out-of-bounds read in mi_clz32 and mi_ctz32#134149
vedant713 wants to merge 8 commits into
python:mainfrom
vedant713:fix-mimalloc-bug

Conversation

@vedant713

Copy link
Copy Markdown

FixesGH-134070

Summary:
This patch adds a masking operation to the index calculation in mi_ctz32() and mi_clz32() functions to prevent out-of-bounds access on 64-bit systems, matching the fix from upstream mimalloc.

Why:
On systems where unsigned long is 64-bit, the multiplication may produce a value >31, causing a read outside the array bounds.

@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ZeroIntensityZeroIntensity changed the title Fix: Prevent out-of-bounds read in mi_clz32 and mi_ctz32 (#134070)gh-134070: Prevent out-of-bounds read in mi_clz32 and mi_ctz32 (#134070)May 17, 2025
@ZeroIntensityZeroIntensity added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels May 17, 2025
@ZeroIntensityZeroIntensity changed the title gh-134070: Prevent out-of-bounds read in mi_clz32 and mi_ctz32 (#134070)gh-134070: Prevent out-of-bounds read in mi_clz32 and mi_ctz32May 17, 2025

@ZeroIntensityZeroIntensity 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.

Please add a test and blurb.

@collinfunk

Copy link
Copy Markdown
Contributor

FYI, this code is from https://github.com/microsoft/mimalloc. You might want to send a pull request there too.

@picnixz

Copy link
Copy Markdown
Member

It's said to be fixed in microsoft/mimalloc@ed31847.

@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@picnixz

Copy link
Copy Markdown
Member

Please, stop updating two PRs at the same time. See https://devguide.python.org/getting-started/pull-request-lifecycle/. I am going to close the other PR as it only contains the NEWS entry. In addition, please do not merge main into this branch if there is no conflict. TiA.

@vedant713

Copy link
Copy Markdown
Author

I'm trying to add via heroku app but giving server error
bedevere/news
bedevere/news — No news entry in Misc/NEWS.d/next/ or "skip news" label found

@picnixz

picnixz commented May 17, 2025

Copy link
Copy Markdown
Member

I never used the app, so I'd suggest using the command-line instead:

python -m pip install blurbpython -m blurbgit commit -m 'blurb'

@picnixz
picnixz marked this pull request as draft May 17, 2025 20:33
@vedant713
vedant713 marked this pull request as ready for review May 17, 2025 21:52
@collinfunk

Copy link
Copy Markdown
Contributor

@picnixz Thanks for checking. Somehow I missed that commit in mimalloc.

@colesbury

Copy link
Copy Markdown
Contributor

I think we should copy-paste the change from upstream instead of doing a similar (but not identical) fix here.

In other words, copy this code from upstream (from the fix commit) into our mimalloc/internal.h file.

https://github.com/microsoft/mimalloc/blob/ed318471126918fce7caf0001cf1e0c78f95173e/include/mimalloc/internal.h#L875-L932

@picnixz

Copy link
Copy Markdown
Member

@vedant713 Are you still working on this one?

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 24, 2026
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 30, 2026
@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label May 31, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesneeds backport to 3.15pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Out-of-bounds read in integrated mimalloc (fixed upstream)

6 participants

@vedant713@collinfunk@picnixz@colesbury@ZeroIntensity@serhiy-storchaka