Skip to content

Add overflow checks before calling memory allocators #127681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
picnixz opened this issue Dec 6, 2024 · 2 comments
Open

Add overflow checks before calling memory allocators #127681

picnixz opened this issue Dec 6, 2024 · 2 comments
Labels
extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) stale Stale PR or inactive for long period of time. type-bug An unexpected behavior, bug, or error

Comments

@picnixz
Copy link
Member

picnixz commented Dec 6, 2024

Bug report

Bug description:

From capi-workgroup/decisions#50 (comment) and capi-workgroup/decisions#50 (comment).

Some calls to the PyMem_* API uses an arithmetic operation on the size, which could make the requested length overflow. The checks in the corresponding functions would not be relevant since the inputs already overflowed.

See #127686 (comment) for the future of this issue.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@picnixz picnixz added the type-bug An unexpected behavior, bug, or error label Dec 6, 2024
@picnixz picnixz self-assigned this Dec 6, 2024
@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) extension-modules C modules in the Modules dir labels Dec 6, 2024
@serhiy-storchaka
Copy link
Member

In most cases there is such check (I myself added and reviewed miriads of checks). If it is forgotten in some case, it is a bug.

@picnixz
Copy link
Member Author

picnixz commented Dec 6, 2024

I've found quite a lot of code that does not check them. There are some parts that do not need such checks because of some assumptions (e.g., when converting numbers to string, we likely won't have more digits than SIZE_MAX).

EDIT: I'll create a fresh branch without comments and with the minimal checks.

@picnixz picnixz removed their assignment Feb 15, 2025
@picnixz picnixz added the stale Stale PR or inactive for long period of time. label Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) stale Stale PR or inactive for long period of time. type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants