classification
Title: ctypes: structure with bitfields as argument
Type: crash Stage:
Components: ctypes Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, alex, amaury.forgeotdarc, arigo, belopolsky, eli.bendersky, meador.inge, python-dev, theller, vinay.sajip
Priority: normal Keywords: patch

Created on 2012-11-29 04:53 by arigo, last changed 2020-01-12 07:46 by vinay.sajip.

Files
File name Uploaded Description Edit
test185_lib.tgz arigo, 2012-11-29 04:53
test186_lib.tgz arigo, 2012-11-29 05:24
issue16576.docfix.1.patch eli.bendersky, 2013-03-06 15:02
Pull Requests
URL Status Linked Edit
PR 15839 vinay.sajip, 2019-09-10 11:38
PR 17097 merged vinay.sajip, 2019-11-09 09:02
PR 17223 merged miss-islington, 2019-11-18 12:29
PR 17224 merged miss-islington, 2019-11-18 12:30
Messages (10)
msg176629 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2012-11-29 04:53
ctypes pretends to support passing arguments to C functions that are structures containing bitfields, or at least does not explicitly forbid it.  But doing so results in misbehavior or segfaults in libffi itself.  Indeed, libffi has no support for this, and ctypes just describes a field like "int x:1;" as "int x;".  The attached example segfaults on Linux x86-64.
msg176631 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2012-11-29 05:24
The same misbehavior occurs if the structures are packed ("_pack_ = 1").  Attached in test186_lib.tgz.
msg183595 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-03-06 15:02
I propose to start with the attached documentation fix (generated vs. 3.2 but should be applied to all active branches).

A code fix has to be discussed more thoroughly because in theory some code running only on x86-32 can rely on it and will break.
msg183665 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-03-07 14:32
The patch addresses issue16575 as well
msg183816 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-03-09 13:56
New changeset 0acd9408b6f1 by Eli Bendersky in branch '3.2':
Add warning in ctypes documentation for #16575 and #16576
http://hg.python.org/cpython/rev/0acd9408b6f1

New changeset bfc159f8e4b4 by Eli Bendersky in branch '3.3':
Add warning in ctypes documentation for #16575 and #16576
http://hg.python.org/cpython/rev/bfc159f8e4b4

New changeset 502624235c7b by Eli Bendersky in branch 'default':
Add warning in ctypes documentation for #16575 and #16576
http://hg.python.org/cpython/rev/502624235c7b
msg183818 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-03-09 13:57
New changeset eece32440a52 by Eli Bendersky in branch '2.7':
Add warning in ctypes documentation for #16575 and #16576
http://hg.python.org/cpython/rev/eece32440a52
msg356447 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-11-12 12:29
New changeset 106271568c58cfebae58f0c52b640dbe716ba2ce by Vinay Sajip in branch 'master':
bpo-16576: Add checks for bitfields passed by value to functions. (GH-17097)
https://github.com/python/cpython/commit/106271568c58cfebae58f0c52b640dbe716ba2ce
msg356869 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-11-18 14:29
New changeset bef2815533011be9f0ce5fa2965bcada76b509b8 by Vinay Sajip (Miss Islington (bot)) in branch '3.8':
bpo-16576: Add checks for bitfields passed by value to functions. (GH-17097) (GH-17223)
https://github.com/python/cpython/commit/bef2815533011be9f0ce5fa2965bcada76b509b8
msg357224 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-11-21 21:47
New changeset 91c15a542cb780377dcde8fc17ba93111bc1d1cf by Vinay Sajip (Miss Islington (bot)) in branch '3.7':
[3.7] bpo-16576: Add checks for bitfields passed by value to functions. (GH-17097) (GH-17224)
https://github.com/python/cpython/commit/91c15a542cb780377dcde8fc17ba93111bc1d1cf
msg359835 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-01-12 07:46
The issue is being reopened, see this comment on bpo-16575:

https://bugs.python.org/msg359834
History
Date User Action Args
2020-01-12 07:46:05vinay.sajipsetstatus: closed -> open
resolution: fixed ->
messages: + msg359835

stage: resolved ->
2019-11-21 22:33:24vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-11-21 21:47:26vinay.sajipsetmessages: + msg357224
2019-11-18 14:29:21vinay.sajipsetmessages: + msg356869
2019-11-18 12:30:01miss-islingtonsetpull_requests: + pull_request16725
2019-11-18 12:29:24miss-islingtonsetpull_requests: + pull_request16724
2019-11-12 12:29:43vinay.sajipsetmessages: + msg356447
2019-11-09 09:02:07vinay.sajipsetpull_requests: + pull_request16603
2019-11-07 21:11:15vinay.sajipsetversions: + Python 3.7, Python 3.8, Python 3.9, - Python 2.7, Python 3.2
2019-09-10 11:38:40vinay.sajipsetstage: patch review
pull_requests: + pull_request15486
2017-02-23 08:18:38vinay.sajipsetnosy: + vinay.sajip
2013-03-09 13:57:29python-devsetmessages: + msg183818
2013-03-09 13:56:19python-devsetnosy: + python-dev
messages: + msg183816
2013-03-07 14:32:39eli.benderskysetnosy: + theller
messages: + msg183665
2013-03-06 15:03:39eli.benderskysetnosy: + amaury.forgeotdarc, belopolsky
2013-03-06 15:03:12eli.benderskysetfiles: - issue16576.docfix.1.patch
2013-03-06 15:03:01eli.benderskysetmessages: - msg183596
2013-03-06 15:02:44eli.benderskysetfiles: + issue16576.docfix.1.patch

messages: + msg183596
2013-03-06 15:02:43eli.benderskysetfiles: + issue16576.docfix.1.patch
keywords: + patch
messages: + msg183595
2013-03-06 14:43:54eli.benderskysetnosy: + eli.bendersky
2012-12-14 08:30:32Arfreversetnosy: + Arfrever
2012-12-11 06:19:46meador.ingesetnosy: + meador.inge
2012-11-29 05:24:20arigosetfiles: + test186_lib.tgz

messages: + msg176631
2012-11-29 04:54:30alexsetnosy: + alex
2012-11-29 04:53:32arigocreate