Skip to content

safe_power(): CID 1426161: Integer handling issues (DIVIDE_BY_ZERO) #76523

Closed

Description

@vstinner
BPO 32342
Nosy @vstinner, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2017-12-15.21:43:37.947>
created_at = <Date 2017-12-15.21:39:12.963>
labels = ['interpreter-core', '3.7', 'invalid']
title = 'safe_power(): CID 1426161:  Integer handling issues  (DIVIDE_BY_ZERO)'
updated_at = <Date 2017-12-15.21:43:37.946>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2017-12-15.21:43:37.946>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2017-12-15.21:43:37.947>
closer = 'vstinner'
components = ['Interpreter Core']
creation = <Date 2017-12-15.21:39:12.963>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 32342
keywords = []
message_count = 2.0
messages = ['308428', '308429']
nosy_count = 2.0
nosy_names = ['vstinner', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue32342'
versions = ['Python 3.7']

Activity

  1. vstinner commented on Dec 15, 2017

    @vstinner
    MemberAuthor

    Coverity found an issue in the commit 2e3f570 (bpo-30416).

    New defect(s) Reported-by: Coverity Scan
    Showing 1 of 1 defect(s)

    ** CID 1426161: Integer handling issues (DIVIDE_BY_ZERO)
    /Python/ast_opt.c: 219 in safe_power()

    ________________________________________________________________________________________________________
    *** CID 1426161:  Integer handling issues  (DIVIDE_BY_ZERO)
    /Python/ast_opt.c: 219 in safe_power()
    213         if (PyLong_Check(v) && PyLong_Check(w) && Py_SIZE(v) && Py_SIZE(w) > 0) {
    214             size_t vbits = _PyLong_NumBits(v);
    215             size_t wbits = PyLong_AsSize_t(w);
    216             if (vbits == (size_t)-1 || wbits == (size_t)-1) {
    217                 return NULL;
    218             }
    >>>     CID 1426161:  Integer handling issues  (DIVIDE_BY_ZERO)
    >>>     In expression "128UL / wbits", division by expression "wbits" which may be zero has undefined behavior.
    219             if (vbits > MAX_INT_SIZE / wbits) {
    220                 return NULL;
    221             }
    222         }
    223
    224         return PyNumber_Power(v, w, Py_None);
  2. added
    3.7 (EOL)
    interpreter-core
    on Dec 15, 2017
  3. vstinner commented on Dec 15, 2017

    @vstinner
    MemberAuthor

    PyLong_AsSize_t(w) cannot be zero thanks to Py_SIZE(w) > 0. I classified the issue as a false positive. Sorry for the noise.

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.7 (EOL)interpreter-core

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions