[issue33632] undefined behaviour: signed integer overflow in threadmodule.c

STINNER Victor report at bugs.python.org
Mon Dec 6 08:26:08 EST 2021


STINNER Victor <vstinner at python.org> added the comment:

> I think PR https://github.com/python/cpython/pull/28674 has resolved this issue.

You're right.

_threadmodule.c now uses _PyDeadline_Init() which calls _PyTime_Add(), and _PyTime_Add() prevents integer overflows; Extract of its implementation:

// Compute t1 + t2. Clamp to [_PyTime_MIN; _PyTime_MAX] on overflow.
static inline int
pytime_add(_PyTime_t *t1, _PyTime_t t2)
{
    if (t2 > 0 && *t1 > _PyTime_MAX - t2) {
        *t1 = _PyTime_MAX;
        return -1;
    }
    else if (t2 < 0 && *t1 < _PyTime_MIN - t2) {
        *t1 = _PyTime_MIN;
        return -1;
    }
    else {
        *t1 += t2;
        return 0;
    }
}

----------
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
superseder:  -> threading.Lock.acquire(timeout) should use sem_clockwait(CLOCK_MONOTONIC)

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33632>
_______________________________________


More information about the Python-bugs-list mailing list