Issue #19437: Fix PyImport_ImportModuleLevelObject(), handle
PyUnicode_Substring() failure (ex: MemoryError)
diff --git a/Python/import.c b/Python/import.c
index c96106f..ad181a2 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1364,7 +1364,11 @@
                 goto error;
             }
         }
+
         base = PyUnicode_Substring(package, 0, last_dot);
+        if (base == NULL)
+            goto error;
+
         if (PyUnicode_GET_LENGTH(name) > 0) {
             PyObject *borrowed_dot, *seq = NULL;