Issue 15261: os.stat(fd) crashes on Windows if fd does not exist (original) (raw)
This issue has been migrated to GitHub: https://github.com/python/cpython/issues/59466
classification
Title: | os.stat(fd) crashes on Windows if fd does not exist | ||
---|---|---|---|
Type: | crash | Stage: | resolved |
Components: | Versions: | Python 3.3 |
process
Status: | closed | Resolution: | fixed |
---|---|---|---|
Dependencies: | Superseder: | ||
Assigned To: | Nosy List: | amaury.forgeotdarc, larry, python-dev, sbt | |
Priority: | high | Keywords: |
Created on 2012-07-06 00:03 by sbt, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (7) | ||
---|---|---|
msg164705 - (view) | Author: Richard Oudkerk (sbt) * ![]() |
Date: 2012-07-06 00:03 |
In Python 3.3 (but not earlier) os.stat() is documented to work with file descriptors. (os.path.exists() also works with fds since it is implemented in terms of os.stat(), although that is *not* documented.) However, on Windows if fd is not open then os.stat(fd) triggers an assertion error or crash: File: f:\dd\vctools\crt_bld\self_x86\crt\src\osfinfo.c Line: 316 Expression: (_osfile(fh) & FOPEN) Note that os.fstat() fails on Windows with OSError(EBADF, ...). | ||
msg164706 - (view) | Author: Richard Oudkerk (sbt) * ![]() |
Date: 2012-07-06 00:10 |
This can probably be fixed by using _PyVerify_fd(). | ||
msg164717 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * ![]() |
Date: 2012-07-06 07:49 |
Many os functions started to accept file descriptors. I don't know how many are available on Windows, but IMO _PyVerify_fd() could be used for all of them; it's a no-op macro on Unix anyway. | ||
msg164719 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2012-07-06 11:23 |
New changeset 62b9bfbc3356 by Richard Oudkerk in branch 'default': Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open. http://hg.python.org/cpython/rev/62b9bfbc3356 | ||
msg164720 - (view) | Author: Richard Oudkerk (sbt) * ![]() |
Date: 2012-07-06 11:36 |
> Many os functions started to accept file descriptors. > I don't know how many are available on Windows... On Windows os.stat() seems to be the only one: >>> os.supports_fd {} | ||
msg164723 - (view) | Author: Larry Hastings (larry) * ![]() |
Date: 2012-07-06 14:16 |
The 62b9bfbc3356 changeset does more than add the guard against invalid file handles; it also adds documentation to os.path.exists documenting that it now accepts path-as-int-fd. While this modification is fine in principle I would have preferred it was submitted separately. | ||
msg164732 - (view) | Author: Richard Oudkerk (sbt) * ![]() |
Date: 2012-07-06 15:55 |
Sorry about that... |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:57:32 | admin | set | github: 59466 |
2012-07-06 15:55:38 | sbt | set | messages: + |
2012-07-06 14:16:55 | larry | set | messages: + |
2012-07-06 12:45:27 | sbt | set | status: open -> closedresolution: fixedstage: needs patch -> resolved |
2012-07-06 11:36:25 | sbt | set | messages: + |
2012-07-06 11:23:42 | python-dev | set | nosy: + python-devmessages: + |
2012-07-06 07:49:39 | amaury.forgeotdarc | set | nosy: + amaury.forgeotdarc, larrymessages: + |
2012-07-06 00:10:01 | sbt | set | messages: + |
2012-07-06 00:03:25 | sbt | create |