https://github.com/python/cpython/commit/800d37feca2e0ea3343995b3b817b653db2f9034
commit: 800d37feca2e0ea3343995b3b817b653db2f9034
branch: main
author: Hood Chatham <[email protected]>
committer: ambv <[email protected]>
date: 2025-07-19T21:43:50+02:00
summary:

gh-124621: Emscripten: Fix regression in use-after-close error handling 
(#136837)

files:
M Python/emscripten_syscalls.c

diff --git a/Python/emscripten_syscalls.c b/Python/emscripten_syscalls.c
index bd5cc07071f20e..886262acbc6810 100644
--- a/Python/emscripten_syscalls.c
+++ b/Python/emscripten_syscalls.c
@@ -148,10 +148,17 @@ EM_JS_MACROS(__externref_t, __maybe_fd_read_async, (
     size_t iovcnt,
     __wasi_size_t *nread
 ), {
-    var stream = SYSCALLS.getStreamFromFD(fd);
     if (!WebAssembly.promising) {
         return null;
     }
+    var stream;
+    try {
+        stream = SYSCALLS.getStreamFromFD(fd);
+    } catch (e) {
+        // If the fd was already closed or never existed, getStreamFromFD()
+        // raises. We'll let fd_read_orig() handle setting errno.
+        return null;
+    }
     if (!stream.stream_ops.readAsync) {
         // Not an async device. Fall back to __wasi_fd_read_orig().
         return null;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to