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

fix: avoid crash on Windows when passing invalid file to compile function #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vthib
Copy link

@vthib vthib commented Mar 9, 2025

When providing a file to the compile function, the PyObject_AsFileDescriptor function is used, which is safe to use on any object type: if the object is not a file, -1 is returned.

However, this value was passed straight to a call to dup() without checking for its validity. This isn't much of an issue on unix where the dup call will simply fail as well and return -1, but it is very much an issue on windows where passing an invalid fd to dup will invoke the invalid parameter handler, which isn't set, so it will simply terminate the program.

In other words, passing anything but a file to the file parameter of the compile function will make the program crash on Windows.

When providing a file to the compile function, the PyObject_AsFileDescriptor
function is used, which is safe to use on any object type: if the object is
not a file, -1 is returned.

However, this value was passed straight to a call to dup() without checking
for its validity. This isn't much of an issue on unix where the dup call will
simply fail as well and return -1, but it is very much an issue on windows
where passing an invalid fd to dup will invoke the invalid parameter handler,
which isn't set, so it will simply terminate the program.

In other words, passing anything but a file to the file parameter
of the compile function will make the program crash on Windows.
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

Successfully merging this pull request may close these issues.

1 participant