Issue 29649: struct.pack_into check boundary error message ignores offset (original) (raw)

Created on 2017-02-25 13:53 by louielu, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 424 merged andrewnester,2017-03-03 12:41
Messages (11)
msg288564 - (view) Author: Louie Lu (louielu) * Date: 2017-02-25 13:53
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 "", line 1, in struct.error: pack_into requires a buffer of at least 1 bytes Since offset is setting at 5, it should at least need `offset + soself->s_size` bytes to store it.
msg288882 - (view) Author: Andrew Nester (andrewnester) * Date: 2017-03-03 12:41
Thanks! Just added PR fixing this.
msg288884 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-03 13:41
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.
msg288885 - (view) Author: Andrew Nester (andrewnester) * Date: 2017-03-03 13:44
yeah, I also thought about this too. Something like 'pack_into requires a buffer of at least 6 bytes (size is 1, offset is 5)'
msg288886 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-03 13:56
Or "pack_into requires a buffer of at least 6 bytes for packing 1 bytes at offset 5".
msg288887 - (view) Author: Andrew Nester (andrewnester) * Date: 2017-03-03 14:01
thanks Serhiy! just implemented your variant in my PR.
msg288978 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-04 13:55
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) struct.pack_into('<B', bytearray(10), -11, 123)
msg289021 - (view) Author: Andrew Nester (andrewnester) * Date: 2017-03-05 16:33
Thanks Serhiy! Just implemented new error messages in my PR for case you mentioned.
msg290081 - (view) Author: Andrew Nester (andrewnester) * Date: 2017-03-24 11:27
any updates on this issue? looks like PR is ready to go
msg291119 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-04 10:46
New changeset f78b119364b521307237a1484ba5f43f42300898 by Serhiy Storchaka (Andrew Nester) in branch 'master': bpo-29649: Improve struct.pack_into() boundary error messages (#424) https://github.com/python/cpython/commit/f78b119364b521307237a1484ba5f43f42300898
msg291120 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-04 10:47
Thank you for your contribution Andrew.
History
Date User Action Args
2022-04-11 14:58:43 admin set github: 73835
2017-04-04 10:47:37 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2017-04-04 10:46:28 serhiy.storchaka set messages: +
2017-03-24 11:27:30 andrewnester set messages: +
2017-03-05 16:33:21 andrewnester set messages: +
2017-03-04 13:55:49 serhiy.storchaka set assignee: serhiy.storchakamessages: +
2017-03-03 21🔞25 terry.reedy set title: struct.pack_into check boundary error message didn't respect offset -> struct.pack_into check boundary error message ignores offsettype: enhancementstage: patch review
2017-03-03 14:01:13 andrewnester set messages: +
2017-03-03 13:56:47 serhiy.storchaka set messages: +
2017-03-03 13:44:35 andrewnester set messages: +
2017-03-03 13:41:45 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2017-03-03 12:41:53 andrewnester set nosy: + andrewnestermessages: +
2017-03-03 12:41:28 andrewnester set pull_requests: + <pull%5Frequest354>
2017-02-25 13:53:04 louielu create