Open Agomik opened 6 months ago
Sorry for the long delay, @Agomik. I was able to reproduce the problem with the following code:
import _xxsubinterpreters as _interpreters
interpid1 = _interpreters.create()
interpid2 = _interpreters.create()
_interpreters.run_string(interpid1, 'import urllib.request')
_interpreters.run_string(interpid2, 'import urllib.request')
Output:
Debug memory block at address p=0x7f84adf92ef0: API ''
2314885530296122877 bytes originally requested
The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd):
at p-7: 0xfd
at p-6: 0xfd
at p-5: 0xfd
at p-4: 0xfd
at p-3: 0xdd *** OUCH
at p-2: 0xdd *** OUCH
at p-1: 0xdd *** OUCH
Because memory is corrupted at the start, the count of bytes requested
may be bogus, and checking the trailing pad bytes may segfault.
The 8 pad bytes at tail=0x20209fa4aef72ced are Segmentation fault (core dumped)
I was also able to verify that the problem is gone in 3.13.
I'll look into what the fix was in 3.13 and if there is any chance we could backport it to 3.12.
Crash report
What happened?
I wrote a single-threaded C++ code using Python C APIs where I start two subinterpreters Sub1 and Sub2, then I load a module M with both. If M imports certain modules (such as urllib.request or yaml), importing M with Sub2 triggers a memory corruption error if Sub1 already imported it. It works instead if M imports some other modules (such as urllib, base64, os or sys).
Here is a snippet that reproduces the error:
Here is the example Python code I used:
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response