Skip to content

Incorrect use of _PyLong_CompactValue() #121153

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

Closed
serhiy-storchaka opened this issue Jun 29, 2024 · 1 comment
Closed

Incorrect use of _PyLong_CompactValue() #121153

serhiy-storchaka opened this issue Jun 29, 2024 · 1 comment
Labels
3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jun 29, 2024

Bug report

There are several errors related to use of _PyLong_CompactValue() in longobject.c.

  • The result has type Py_ssize_t, not intptr_t. Although on most supported platforms it is the same.
  • Type cast from unsigned integer to signed integer and from signed integer to unsigned integer should be explicit.
  • Downcasting should be explicit.

Some of the current code may have undefined behavior.

Linked PRs

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error 3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes labels Jun 29, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jun 29, 2024
* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jun 29, 2024
* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jun 29, 2024
* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
vstinner added a commit to vstinner/cpython that referenced this issue Jul 9, 2024
@markshannon
Copy link
Member

The result has type Py_ssize_t, not intptr_t. Although on most supported platforms it is the same.

We should change the return type to intptr_t in that case. I thought it was.

serhiy-storchaka added a commit that referenced this issue Jul 13, 2024
)

* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 17, 2024
…lue() (pythonGH-121154)

* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
(cherry picked from commit 1801545)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 17, 2024
…lue() (pythonGH-121154)

* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
(cherry picked from commit 1801545)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Jul 17, 2024
…H-121154)

* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signed integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
(cherry picked from commit 1801545)
serhiy-storchaka added a commit that referenced this issue Jul 17, 2024
…H-121154) (GH-121900)

* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signed integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
(cherry picked from commit 1801545)
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
…ythonGH-121154)

* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants