Skip to content
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

4.2.0 crashes upon import with 32 bit python versions #317

Closed
daxie117 opened this issue Apr 22, 2024 · 2 comments
Closed

4.2.0 crashes upon import with 32 bit python versions #317

daxie117 opened this issue Apr 22, 2024 · 2 comments
Assignees
Milestone

Comments

@daxie117
Copy link

daxie117 commented Apr 22, 2024

We are running into an error upon import, error trace pasted below:

import bitstring
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\<path>\python\3117\test\Lib\site-packages\bitstring\__init__.py", line 197, in <module>
    DtypeDefinition('uintle', Bits._setuintle, Bits._getuintle, int, False, uint_bits2chars,
  File "C:\<path>\python\3117\test\Lib\site-packages\bitstring\dtypes.py", line 275, in __init__
    if self.allowed_lengths:
  File "C:\<path>\python\3117\test\Lib\site-packages\bitstring\dtypes.py", line 244, in __len__
    return len(self.value)
           ^^^^^^^^^^^^^^^
OverflowError: Python int too large to convert to C ssize_t

https://github.com/scott-griffiths/bitstring/blame/main/bitstring/dtypes.py#L230
traced it down to this line when the module attempts to calculate allowed sizes. It works fine on 64 bit python, but the generator expression here:

https://github.com/scott-griffiths/bitstring/blame/main/bitstring/dtypes.py#L231
self.value = range(value[0], infinity, step)

causes the length of self.value to exceed the max ssize_t (presumably 4 bytes).

@scott-griffiths
Copy link
Owner

Thank you for the swift bug report.

Ah, 32-bit Python. That brings back memories. The fix should be trivial (what could possibly go wrong hard-coding a value for infinity?!) but I'll probably wait a day to see if anything else has broken before releasing a 4.2.1.

Now I just have to work out how to get the CI to target a 32-bit Python....

@scott-griffiths
Copy link
Owner

This should now be fixed in 4.2.1. although I couldn't find a way to add the test on 32-bit Python to the CI, so strictly speaking I haven't tested the fix actually works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants