Граф коммитов

1 Коммитов

Автор SHA1 Сообщение Дата
heinrich5991 e25301b243 Check for integer overflows in Python bindings
Not spelling out the numbers as numbers is fine, CPython optimizes it
out:
```py
>>> import dis
>>> dis.dis("not -2**63 <= value < 2**63")
  0           0 RESUME                   0

  1           2 LOAD_CONST               0 (-9223372036854775808)
              4 LOAD_NAME                0 (value)
              6 SWAP                     2
              8 COPY                     2
             10 COMPARE_OP               1 (<=)
             16 JUMP_IF_FALSE_OR_POP     5 (to 28)
             18 LOAD_CONST               1 (9223372036854775808)
             20 COMPARE_OP               0 (<)
             26 JUMP_FORWARD             2 (to 32)
        >>   28 SWAP                     2
             30 POP_TOP
        >>   32 UNARY_NOT
             34 RETURN_VALUE
```

The exception thrown imitates the one of the `struct` module:
```py
>>> import struct
>>> struct.pack("<I", 2**32)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: 'I' format requires 0 <= number <= 4294967295
```

Also add some tests exercising these code paths.

Fixes #1540.
2023-05-17 10:20:01 +02:00