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
struct.pack_into check boundary error message ignores offset #73835
Comments
For this situation, check boundary error message didn't correctly show out. >>> import struct
>>> import ctypes
>>> byte_list = ctypes.create_string_buffer(1)
>>> struct.pack_into('b', byte_list, 5, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: pack_into requires a buffer of at least 1 bytes Since offset is setting at 5, it should at least need |
Thanks! Just added PR fixing this. |
I'm not sure the new error message is better. It is not known what is wrong -- the size of the buffer, or the offset? I think that the better error message should include three numbers: the offset, the size of the destination buffer, and the size of packed data or the minimal size of the destination buffer. |
yeah, I also thought about this too. |
Or "pack_into requires a buffer of at least 6 bytes for packing 1 bytes at offset 5". |
thanks Serhiy! just implemented your variant in my PR. |
Different error messages are needed if original offset < 0. For example packing 4 bytes with offset -2 always fails, not depending of the size of the buffer. Packing into buffer of size 10 with offset -11 always fails, not depending of the size of packed data. struct.pack_into('<I', bytearray(10), -2, 123) |
Thanks Serhiy! Just implemented new error messages in my PR for case you mentioned. |
any updates on this issue? looks like PR is ready to go |
Thank you for your contribution Andrew. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: