Skip to content

Python module import crash (Windows) #2154

@boberfly

Description

@boberfly

Hi all,

On this line:

OpenEXR_error = PyErr_NewException ((char*) "OpenEXR.error", NULL, NULL);

We've found that OpenEXR_error returns nullptr and will crash when it is run in the next few lines in PyDict_SetItemString. I've made the following patch to bypass this:

--- a/src/wrappers/python/PyOpenEXR_old.cpp	2025-10-20 13:41:28.625622100 +1100
+++ b/src/wrappers/python/PyOpenEXR_old.cpp	2025-10-20 13:41:35.439505100 +1100
@@ -1572,8 +1572,11 @@
     PyModule_AddObject (module, "OutputFile", (PyObject*) &OutputFile_Type);
 
     OpenEXR_error = PyErr_NewException ((char*) "OpenEXR.error", NULL, NULL);
-    PyDict_SetItemString (moduleDict, "error", OpenEXR_error);
-    Py_DECREF (OpenEXR_error);
+    if (OpenEXR_error)
+    {
+        PyDict_SetItemString (moduleDict, "error", OpenEXR_error);
+        Py_DECREF (OpenEXR_error);
+    }
 
     PyObject *item;
 

But I'm not entirely familiar with the codebase to know if this is a valid workaround or it is just bypassing something else. With this workaround I'm able to import the module successfully without a crash.

I built this with the following:
MSVC 14.43.x
Windows 10
Python 3.11.4
Pybind11 2.9.2

Kind regards
-Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions