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

2021-12-06 Thread STINNER Victor


STINNER Victor  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-12-05 Thread hongweipeng


hongweipeng  added the comment:

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

--
nosy: +hongweipeng

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-04-15 Thread Paul Ganssle


Paul Ganssle  added the comment:

> In short, a+b can overflow, but a-b cannot?

I think it's more that by always checking the elapsed time against `now() - 
starttime`, you never need to represent the time at which the timeout should 
happen - which may be so far in the future that it causes a signed overflow.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-04-15 Thread STINNER Victor


STINNER Victor  added the comment:

In short, a+b can overflow, but a-b cannot?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-04-14 Thread Martin Panter

Martin Panter  added the comment:

Victor, if you run the test suite, one of the test cases should trigger the 
overflow. I used to compile with Undefined Behaviour Sanitizer to print 
messages when these errors occur; see 
 for my setup at the time. I 
presume Antoine did something similar.

I do not remember, but suspect the test case might be the following lines of 
“BaseLockTests.test_timeout” in Lib/test/lock_tests.py, testing a fraction of a 
second less than PY_TIMEOUT_MAX:

# TIMEOUT_MAX is ok
lock.acquire(timeout=TIMEOUT_MAX)

Perhaps reducing PY_TIMEOUT_MAX by a few centuries would be one way to avoid 
the problem. In my patch I avoided the problem by rearranging the arithmetic, 
so that the timeout value is only compared and reduced, never added.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-04-08 Thread Paul Ganssle


Change by Paul Ganssle :


--
nosy: +p-ganssle

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-04-08 Thread Zackery Spytz


Zackery Spytz  added the comment:

I've created a PR based on Martin Panter's patch.

--
components: +Extension Modules -Library (Lib)
nosy: +ZackerySpytz
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-04-08 Thread Zackery Spytz


Change by Zackery Spytz :


--
keywords: +patch
pull_requests: +12652
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-05-24 Thread STINNER Victor

STINNER Victor  added the comment:

> Modules/_threadmodule.c:52:47: runtime error: signed integer overflow: 
> 2387971499048 + 92233720360 cannot be represented in type 'long'

How do you reproduce the issue? The thread module should limit the maximum 
timeout to PY_TIMEOUT_MAX. Maybe PY_TIMEOUT_MAX is too big?

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-05-24 Thread Martin Panter

Martin Panter  added the comment:

Looks like this is what my thread.patch was fixing in 
. You’re welcome to use my patch, 
but I won’t have time to work on it myself.

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-05-24 Thread Antoine Pitrou

New submission from Antoine Pitrou :

Modules/_threadmodule.c:52:47: runtime error: signed integer overflow: 
2387971499048 + 92233720360 cannot be represented in type 'long'

--
components: Library (Lib)
messages: 317545
nosy: pitrou
priority: normal
severity: normal
status: open
title: undefined behaviour: signed integer overflow in threadmodule.c
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com