Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python / PIL] Crashes when importing #23358

Closed
2 of 6 tasks
kasper93 opened this issue Feb 11, 2025 · 11 comments
Closed
2 of 6 tasks

[Python / PIL] Crashes when importing #23358

kasper93 opened this issue Feb 11, 2025 · 11 comments

Comments

@kasper93
Copy link
Contributor

kasper93 commented Feb 11, 2025

Description / Steps to reproduce the issue

  1. Run rst2pdf python -c "from PIL import Image"

After recent update. Not sure if on all envs, I don't have others installed.

Expected behavior

Doesn't crash.

Actual behavior

Crashes somewhere in PIL it looks like.

[0x0]   _imaging_cp312_mingw_x86_64_ucrt_llvm!PyInit__imaging+0x56a84   0xf322df9b18   0x7fff286e1efa   
[0x1]   _imaging_cp312_mingw_x86_64_ucrt_llvm!PyInit__imaging+0x4085a   0xf322df9b20   0x7fff286a1827   
[0x2]   _imaging_cp312_mingw_x86_64_ucrt_llvm!PyInit__imaging+0x187   0xf322df9b60   0x7fff151ff35e   
[0x3]   libpython3_12!PyImport_IsInitialized+0x58e   0xf322df9bb0   0x7fff151fefab   
[0x4]   libpython3_12!PyImport_IsInitialized+0x1db   0xf322df9c40   0x7fff152598b6   
[0x5]   libpython3_12!PyDict_Size+0x5ee6   0xf322df9c90   0x7fff14ffc210   
[0x6]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322df9ce0   0x7fff150947f6   
[0x7]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322df9f90   0x7fff15049967   
[0x8]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfa000   0x7fff1504981a   
[0x9]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfa0a0   0x7fff15039ba2   
[0xa]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfa100   0x7fff15279333   
[0xb]   libpython3_12!PyInit__tokenize+0x1603   0xf322dfa1d0   0x7fff152599ab   
[0xc]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfa290   0x7fff14ffc210   
[0xd]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfa2e0   0x7fff150947f6   
[0xe]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfa590   0x7fff15049967   
[0xf]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfa600   0x7fff1504981a   
[0x10]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfa6a0   0x7fff150394b8   
[0x11]   libpython3_12!PyImport_ImportModuleLevelObject+0x5a8   0xf322dfa700   0x7fff150001b0   
[0x12]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dfa7d0   0x7fff1515f7e5   
[0x13]   libpython3_12!PyEval_EvalCode+0x115   0xf322dfaa80   0x7fff1527a1c2   
[0x14]   libpython3_12!PyInit__tokenize+0x2492   0xf322dfab50   0x7fff152599ab   
[0x15]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfac20   0x7fff14ffc210   
[0x16]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfac70   0x7fff150947f6   
[0x17]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfaf20   0x7fff15049967   
[0x18]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfaf90   0x7fff1504981a   
[0x19]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfb030   0x7fff15039ba2   
[0x1a]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfb090   0x7fff15279333   
[0x1b]   libpython3_12!PyInit__tokenize+0x1603   0xf322dfb160   0x7fff152599ab   
[0x1c]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfb220   0x7fff14ffc210   
[0x1d]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfb270   0x7fff150947f6   
[0x1e]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfb520   0x7fff15049967   
[0x1f]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfb590   0x7fff1504981a   
[0x20]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfb630   0x7fff150394b8   
[0x21]   libpython3_12!PyImport_ImportModuleLevelObject+0x5a8   0xf322dfb690   0x7fff150001b0   
[0x22]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dfb760   0x7fff1515f7e5   
[0x23]   libpython3_12!PyEval_EvalCode+0x115   0xf322dfba10   0x7fff1527a1c2   
[0x24]   libpython3_12!PyInit__tokenize+0x2492   0xf322dfbae0   0x7fff152599ab   
[0x25]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfbbb0   0x7fff14ffc210   
[0x26]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfbc00   0x7fff150947f6   
[0x27]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfbeb0   0x7fff15049967   
[0x28]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfbf20   0x7fff1504981a   
[0x29]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfbfc0   0x7fff15039ba2   
[0x2a]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfc020   0x7fff150001b0   
[0x2b]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dfc0f0   0x7fff1515f7e5   
[0x2c]   libpython3_12!PyEval_EvalCode+0x115   0xf322dfc3a0   0x7fff1527a1c2   
[0x2d]   libpython3_12!PyInit__tokenize+0x2492   0xf322dfc470   0x7fff152599ab   
[0x2e]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfc540   0x7fff14ffc210   
[0x2f]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfc590   0x7fff150947f6   
[0x30]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfc840   0x7fff15049967   
[0x31]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfc8b0   0x7fff1504981a   
[0x32]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfc950   0x7fff15039ba2   
[0x33]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfc9b0   0x7fff150001b0   
[0x34]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dfca80   0x7fff1515f7e5   
[0x35]   libpython3_12!PyEval_EvalCode+0x115   0xf322dfcd30   0x7fff1527a1c2   
[0x36]   libpython3_12!PyInit__tokenize+0x2492   0xf322dfce00   0x7fff152599ab   
[0x37]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfced0   0x7fff14ffc210   
[0x38]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfcf20   0x7fff150947f6   
[0x39]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfd1d0   0x7fff15049967   
[0x3a]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfd240   0x7fff1504981a   
[0x3b]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfd2e0   0x7fff15039ba2   
[0x3c]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfd340   0x7fff150001b0   
[0x3d]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dfd410   0x7fff1515f7e5   
[0x3e]   libpython3_12!PyEval_EvalCode+0x115   0xf322dfd6c0   0x7fff1527a1c2   
[0x3f]   libpython3_12!PyInit__tokenize+0x2492   0xf322dfd790   0x7fff152599ab   
[0x40]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfd860   0x7fff14ffc210   
[0x41]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfd8b0   0x7fff150947f6   
[0x42]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfdb60   0x7fff15049967   
[0x43]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfdbd0   0x7fff1504981a   
[0x44]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfdc70   0x7fff15039ba2   
[0x45]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfdcd0   0x7fff150001b0   
[0x46]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dfdda0   0x7fff1515f7e5   
[0x47]   libpython3_12!PyEval_EvalCode+0x115   0xf322dfe050   0x7fff1527a1c2   
[0x48]   libpython3_12!PyInit__tokenize+0x2492   0xf322dfe120   0x7fff152599ab   
[0x49]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfe1f0   0x7fff14ffc210   
[0x4a]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfe240   0x7fff150947f6   
[0x4b]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfe4f0   0x7fff15049967   
[0x4c]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfe560   0x7fff1504981a   
[0x4d]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfe600   0x7fff15039ba2   
[0x4e]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfe660   0x7fff150001b0   
[0x4f]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dfe730   0x7fff1515f7e5   
[0x50]   libpython3_12!PyEval_EvalCode+0x115   0xf322dfe9e0   0x7fff1527a1c2   
[0x51]   libpython3_12!PyInit__tokenize+0x2492   0xf322dfeab0   0x7fff152599ab   
[0x52]   libpython3_12!PyDict_Size+0x5fdb   0xf322dfeb80   0x7fff14ffc210   
[0x53]   libpython3_12!PyEval_EvalFrameDefault+0x3be0   0xf322dfebd0   0x7fff150947f6   
[0x54]   libpython3_12!PyObject_VectorcallMethod+0x126   0xf322dfee80   0x7fff15049967   
[0x55]   libpython3_12!PyObject_CallMethodObjArgs+0x1d7   0xf322dfeef0   0x7fff1504981a   
[0x56]   libpython3_12!PyObject_CallMethodObjArgs+0x8a   0xf322dfef90   0x7fff15039ba2   
[0x57]   libpython3_12!PyImport_ImportModuleLevelObject+0xc92   0xf322dfeff0   0x7fff150001b0   
[0x58]   libpython3_12!PyEval_EvalFrameDefault+0x7b80   0xf322dff0c0   0x7fff1515f7e5   
[0x59]   libpython3_12!PyEval_EvalCode+0x115   0xf322dff370   0x7fff1527a1c2   
[0x5a]   libpython3_12!PyInit__tokenize+0x2492   0xf322dff440   0x7fff152599ab   
[0x5b]   libpython3_12!PyDict_Size+0x5fdb   0xf322dff510   0x7fff14ffea0f   
[0x5c]   libpython3_12!PyEval_EvalFrameDefault+0x63df   0xf322dff560   0x7fff1503bf58   
[0x5d]   libpython3_12!PyObject_Call+0x58   0xf322dff810   0x7fff1519e992   
[0x5e]   libpython3_12!Py_wgetcwd+0x152   0xf322dff870   0x7fff1519b23b   
[0x5f]   libpython3_12!Py_RunMain+0x14b   0xf322dff8e0   0x7fff1519a613   
[0x60]   libpython3_12!Py_Main+0x283   0xf322dff9b0   0x7fff1519a3cf   
[0x61]   libpython3_12!Py_Main+0x3f   0xf322dffc20   0x7ff6d4f31340   
[0x62]   python+0x1340   0xf322dffc80   0x7ff6d4f313a6   
[0x63]   python+0x13a6   0xf322dffce0   0x7ffffe41e8d7   

Verification

Windows Version

MINGW64_NT-10.0-26100

MINGW environments affected

  • MINGW64
  • MINGW32
  • UCRT64
  • CLANG64
  • CLANGARM64

Are you willing to submit a PR?

No response

@kasper93 kasper93 added the bug label Feb 11, 2025
@kasper93 kasper93 changed the title [rst2pdf] Crashes. [rst2pdf] Crashes when importing PIL Feb 11, 2025
@Biswa96 Biswa96 added the python label Feb 11, 2025
@Biswa96
Copy link
Member

Biswa96 commented Feb 11, 2025

I can reproduce the issue in my setup. This seems to be a python pillow issue.

$ python -c "from PIL import Image"
Segmentation fault

Here is the output from lldb

(lldb) bt
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffd4c2c8124: Access violation reading location 0xffffffffffffffff
  * frame #0: 0x00007ffd4c2c8124 _imaging.cp312-mingw_x86_64_ucrt_llvm.pyd`PyInit__imaging + 354948
    frame #1: 0x00007ffd43f8bb4e libpython3.12.dll`winconsoleio_spec + 58478
    frame #2: 0x00007ffd43f74078 libpython3.12.dll`_PyRuntime + 458064

@Biswa96
Copy link
Member

Biswa96 commented Feb 11, 2025

@kmilos could you share any info about this issue?

@lazka
Copy link
Member

lazka commented Feb 11, 2025

downgrading pillow helps (before bc3d348)

@lazka
Copy link
Member

lazka commented Feb 11, 2025

same as #23316

#0  0x00007ffff140df54 in liq_version ()
   from C:\msys64\clang64\lib\python3.12\site-packages\PIL\_imaging.cp312-mingw_x86_64_ucrt_llvm.pyd
#1  0x00007ffff13f6b5a in ImagingImageQuantVersion () at src/libImaging/QuantPngQuant.c:128
#2  0x00007ffff13b1837 in setup_module (m=0x1d7b470) at src/_imaging.c:4375
#3  PyInit__imaging () at src/_imaging.c:4465
#4  0x00007fffef62f35e in _PyImport_LoadDynamicModuleWithSpec ()
   from C:\msys64\clang64\bin\libpython3.12.dll
#5  0x00007fffef62efab in _PyImport_IsInitialized () from C:\msys64\clang64\bin\libpython3.12.dll
#6  0x00007fffef6898b6 in cfunction_vectorcall_FASTCALL.llvm.14150209033267026168 ()
   from C:\msys64\clang64\bin\libpython3.12.dll
#7  0x00007fffef42c210 in _PyEval_EvalFrameDefault () from C:\msys64\clang64\bin\libpython3.12.dll
#8  0x00007fffef4c47f6 in _PyObject_VectorcallTstate.llvm.11741584965757615223 ()
   from C:\msys64\clang64\bin\libpython3.12.dll
#9  0x00007fffef479967 in object_vacall.llvm () from C:\msys64\clang64\bin\libpython3.12.dll
#10 0x00007fffef47981a in PyObject_CallMethodObjArgs ()
   from C:\msys64\clang64\bin\libpython3.12.dll
#11 0x00007fffef469ba2 in PyImport_ImportModuleLevelObject ()
   from C:\msys64\clang64\bin\libpython3.12.dll
#12 0x00007fffef6a9333 in _PyAST_ExprAsUnicode () from C:\msys64\clang64\bin\libpython3.12.dll
#13 0x00007fffef6899ab in cfunction_vectorcall_FASTCALL_KEYWORDS.llvm.14150209033267026168 ()
   from C:\msys64\clang64\bin\libpython3.12.dll
#14 0x00007fffef42c210 in _PyEval_EvalFrameDefault () from C:\msys64\clang64\bin\libpython3.12.dll
#15 0x00007fffef4c47f6 in _PyObject_VectorcallTstate.llvm.11741584965757615223 ()
   from C:\msys64\clang64\bin\libpython3.12.dll
#16 0x00007fffef479967 in object_vacall.llvm () from C:\msys64\clang64\bin\libpython3.12.dll

@kasper93 kasper93 changed the title [rst2pdf] Crashes when importing PIL [Python / PIL] Crashes when importing Feb 11, 2025
@lazka
Copy link
Member

lazka commented Feb 11, 2025

Using the old import library from libimagequant 4.3.3-1 (with the new DLL) also fixes the issue, which points to cargo-c creating broken import libs.

@lazka
Copy link
Member

lazka commented Feb 11, 2025

reverting cargo-c doesn't work as the produced import libs with older cargo-c are broken differently with newer rust it seems (it links against an empty string dll which it then doesn't find)

So I'm not sure what to do.

@lazka
Copy link
Member

lazka commented Feb 11, 2025

I'll disable libimagequant support in pillow for now until we know more.

@lazka
Copy link
Member

lazka commented Feb 12, 2025

I've created a reproducer: https://github.com/lazka/cargo-c-crash

@kmilos
Copy link
Contributor

kmilos commented Feb 12, 2025

Sorry @Biswa96, I'm afraid I can't really help here...

@lazka
Copy link
Member

lazka commented Feb 12, 2025

Since the cause is likely cargo-c moving from the toolchain import lib generator to using a rust crate, manually re-creating the importlib with dlltool might be a workaround.

edit: it is

@lazka
Copy link
Member

lazka commented Feb 12, 2025

Deployed a workaround #23364

Closing this.

Upstream issue: lu-zero/cargo-c#443

@lazka lazka closed this as completed Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants