Skip to content
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

Crash on Windows if dunder methods cursed into ctypes.c_int raises an exception #57

Open
EZForever opened this issue Jun 13, 2021 · 0 comments

Comments

@EZForever
Copy link

EZForever commented Jun 13, 2021

In addition to #56, if the dunder method is cursed into ctypes' integer types, a raised exception causes Python to crash on Windows.

Proof of concept:

#!/usr/bin/env python3

from ctypes import c_int
from forbiddenfruit import curse

def c_int_add(self: c_int, other: int) -> c_int:
    raise TypeError('This exception should be caught')

curse(c_int, '__add__', c_int_add)

try:
    print(c_int(1) + 1) # TypeError (correct) then crash on Windows (wrong)
except TypeError:
    print('TypeError caught')

print('If this gets printed then nothing has crashed')

Test result on Windows (version 10.0.19043.1052, Python 3.8.6, both 64-bit):

(venv) C:\dev\test> python bug2.py 
Exception ignored on calling ctypes callback function: <function c_int_add at 0x000001E12AC1FDC0>
Traceback (most recent call last):
  File "E:\src\pytrickz\venv\lib\site-packages\forbiddenfruit\__init__.py", line 328, in wrapper
    return func(*args, **kwargs)
  File "bug2.py", line 7, in c_int_add
    raise TypeError('This exception should be caught')
TypeError: This exception should be caught

(venv) C:\dev\test> echo %=ExitCode%
C0000005

(venv) C:\dev\test> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant