Issue 30242: resolve undefined behaviour in struct (original) (raw)

Created on 2017-05-03 04:30 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1418 merged xiang.zhang,2017-05-03 04:33
PR 1586 merged xiang.zhang,2017-05-15 04:06
PR 1587 merged xiang.zhang,2017-05-15 04:07
PR 1588 merged xiang.zhang,2017-05-15 04:10
Messages (10)
msg292836 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-05-03 04:30
In struct there are several places using code like: p[--i] = (char)x; to extract the least significant byte from a long. Although this behaviour seems to apply to common implementations but it does not conform to C standard.
msg292839 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-03 05:06
I think it is better to change the type of p to unsigned char.
msg292843 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-05-03 05:52
> I think it is better to change the type of p to unsigned char. Good advice.
msg292844 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-03 06:20
I meant changing the type of the first argument of np_ubyte() etc. np_ubyte(unsigned char *p, PyObject *v, const formatdef *f)
msg292845 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-05-03 06:25
Hmm, do we need to? Currently all pack routines accept a char *p. Converting it to unsigned char * inside could also solve the problem.
msg292847 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-03 07:03
Your patch LGTM as a minimal patch for backporting to maintained releases (maybe Mark have other comments). But I think it would be better to make all pointers to raw memory of type unsigned char*. Not just packing, but unpacking too. Using even memcpy between long* and char* is undefined behavior, the source and target should either have the same type, or one of them be unsigned char*.
msg293670 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-05-15 04:04
New changeset 981096f98b9c131594b0ac85ad01b63cbd11aa0a by Xiang Zhang in branch 'master': bpo-30242: resolve some undefined behaviours in struct (#1418) https://github.com/python/cpython/commit/981096f98b9c131594b0ac85ad01b63cbd11aa0a
msg293674 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-05-15 05:17
New changeset aad1caf55f7fadb00ee097a1465bece4e128d8ef by Xiang Zhang in branch '3.6': bpo-30242: resolve some undefined behaviours in struct (#1418) (#1586) https://github.com/python/cpython/commit/aad1caf55f7fadb00ee097a1465bece4e128d8ef
msg293675 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-05-15 05:17
New changeset dd2a09cf98845b1460f0e049ad0ffeeb5c6c6476 by Xiang Zhang in branch '3.5': bpo-30242: resolve some undefined behaviours in struct (#1418) (#1587) https://github.com/python/cpython/commit/dd2a09cf98845b1460f0e049ad0ffeeb5c6c6476
msg293676 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-05-15 05:17
New changeset 982a17e02d99dcf6e4dff93110cff5ecc59247f5 by Xiang Zhang in branch '2.7': bpo-30242: resolve some undefined behaviours in struct (#1418) (#1588) https://github.com/python/cpython/commit/982a17e02d99dcf6e4dff93110cff5ecc59247f5
History
Date User Action Args
2022-04-11 14:58:46 admin set github: 74428
2017-05-15 05:19:43 xiang.zhang set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-05-15 05:17:56 xiang.zhang set messages: +
2017-05-15 05:17:43 xiang.zhang set messages: +
2017-05-15 05:17:30 xiang.zhang set messages: +
2017-05-15 04:10:36 xiang.zhang set pull_requests: + <pull%5Frequest1681>
2017-05-15 04:07:50 xiang.zhang set pull_requests: + <pull%5Frequest1680>
2017-05-15 04:06:47 xiang.zhang set pull_requests: + <pull%5Frequest1679>
2017-05-15 04:04:28 xiang.zhang set messages: +
2017-05-03 07:03:28 serhiy.storchaka set messages: +
2017-05-03 06:25:14 xiang.zhang set messages: +
2017-05-03 06:20:41 serhiy.storchaka set messages: +
2017-05-03 05:52:50 xiang.zhang set messages: +
2017-05-03 05:06:43 serhiy.storchaka set messages: +
2017-05-03 04:33:31 xiang.zhang set pull_requests: + <pull%5Frequest1524>
2017-05-03 04:30:53 xiang.zhang create