[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread STINNER Victor


STINNER Victor  added the comment:

Thanks Meador Inge for the bug report and thanks Sean Gillespie for the fix! It 
just took 9 years to fix this corner case ;-)

Copy of the comment on the PR:
https://github.com/python/cpython/pull/19914#pullrequestreview-419331432

I tried to rewrite _ctypes_callproc() to use PyMem_Malloc() instead of 
alloca(), but it's quite complicated. There are 3 arrays with a length of 
argcount items: args, avalues, atypes. Moreover, resbuf is also allocated with 
alloca(). When using PyMem_Malloc(), error handling is much more complicated.

I also tried to restrict the overall usage of stack memory to 4096 bytes (size 
of one page on x86), but users would be surprised by CTYPES_MAX_ARGCOUNT value.

I would say that raising an exception is better than crashing for a lot of 
arguments. If someone is blocked by this new limitation, in that case we can 
revisit the PyMem_Malloc() idea.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.10, Python 3.7, Python 3.8, Python 3.9 -Python 2.7, Python 
3.2, Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread miss-islington


miss-islington  added the comment:


New changeset a285af7e626d1b81cf09f8b2bf7656f100bc1237 by Miss Islington (bot) 
in branch '3.8':
bpo-13097: ctypes: limit callback to 1024 arguments (GH-19914)
https://github.com/python/cpython/commit/a285af7e626d1b81cf09f8b2bf7656f100bc1237


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread miss-islington


miss-islington  added the comment:


New changeset 1c4dcafd0b025e771f4dbd7197d0b5f263c9cb54 by Miss Islington (bot) 
in branch '3.7':
bpo-13097: ctypes: limit callback to 1024 arguments (GH-19914)
https://github.com/python/cpython/commit/1c4dcafd0b025e771f4dbd7197d0b5f263c9cb54


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread miss-islington


miss-islington  added the comment:


New changeset 788d7bfe189e715eab3855c20ea5d6da0d8bed70 by Miss Islington (bot) 
in branch '3.9':
bpo-13097: ctypes: limit callback to 1024 arguments (GH-19914)
https://github.com/python/cpython/commit/788d7bfe189e715eab3855c20ea5d6da0d8bed70


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread miss-islington


Change by miss-islington :


--
pull_requests: +19709
pull_request: https://github.com/python/cpython/pull/20454

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 6.0 -> 7.0
pull_requests: +19708
pull_request: https://github.com/python/cpython/pull/20453

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread miss-islington


Change by miss-islington :


--
pull_requests: +19710
pull_request: https://github.com/python/cpython/pull/20455

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-27 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 29a1384c040d39659e7d01f1fd7b6eb71ef2634e by Sean Gillespie in 
branch 'master':
bpo-13097: ctypes: limit callback to 1024 arguments (GH-19914)
https://github.com/python/cpython/commit/29a1384c040d39659e7d01f1fd7b6eb71ef2634e


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-04 Thread Roundup Robot


Change by Roundup Robot :


--
keywords: +patch
nosy: +python-dev
nosy_count: 5.0 -> 6.0
pull_requests: +19229
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/19914

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13097] [easy C issue] ctypes: segfault with large number of callback arguments

2020-05-04 Thread STINNER Victor


STINNER Victor  added the comment:

I suggest to raise an exception if it's called with more than 1024 arguments.

--
keywords: +easy (C), newcomer friendly
title: ctypes: segfault with large number of callback arguments -> [easy C 
issue] ctypes: segfault with large number of callback arguments

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com