Skip to content

Packaged app compressed with UPX crashes at startup in Windows x64 #4178

Closed

Description

@MyDataIsReady

If I use UPX, my app crashes as soon as it starts (there's no console output when I use cmd.exe). Weird thing is, bundled app with --onefile works with no issues (files seem to be compressed, *.exe is smaller when I use UPX if I recall correctly).
Everything works well in Windows 7 x86 too.

According to Windows 7 error message, "ucrtbase.dll" fails but according to Windows 10 (x64) error message, "vcruntime140.dll" does, so the workaround is easy: replacing each faulty *.dll file with its non-compressed version. It solves the problem but somewhat extensive testing is would be needed.
Have no tried Windows 8 yet.

OS: Windows 7 x64
UPX: 3.95 (x64 and x86), 3.94 and 3.93
Python: 3.7.3 x86 fresh install
Pyinstaller: 3.4 and 3.5dev0+b54a15d72e (no cache files)
Test toy code:

import os

print("hola")
os.system("pause")

A "hello world" app works though.

I'm new to GitHub so if there's something else I should do or test just tell me.
And thank you very very much for your hard work on PyInstaller!

Activity

  1. cdgriffith commented on Aug 26, 2020

    @cdgriffith

    I am experiencing the same issue on Windows 10, UPX 3.86. Using console and onefile.

    ucrtbase.dll is not designed to run on Windows...Error status: 0xc000007b

  2. bwoodsend commented on Feb 1, 2021

    @bwoodsend
    Member

    I suspect that this was fixed by #5382?

  3. cdgriffith commented on Feb 1, 2021

    @cdgriffith

    With Pyinstaller 4.2 I see the nice message Disabling UPX for c:\program files\python39\VCRUNTIME140_1.dll due to CFG! and no longer receive the error above!

    Still doesn't load when using UPX due to PyQT5 error of qt.qpa.plugin: Could not find the Qt platform plugin "windows" in "" but I am guessing that is something entirely different sigh

  4. rokm commented on Feb 1, 2021

    @rokm
    Member

    Still doesn't load when using UPX due to PyQT5 error of qt.qpa.plugin: Could not find the Qt platform plugin "windows" in "" but I am guessing that is something entirely different sigh

    That's due to upx/upx#107 (which is specific to Qt plugins and unrelated to CFG).

    I suppose if we wanted to work around it, we'd need to exempt Qt5 plugins from UPX-processing. Either via hard-coded list, or by implementing a mechanism that would allow hooks to specify list(s) of files to exempt from UPX (and then have PySide2 and PyQt5 hooks exempt their Qt5 plugins).

  5. cdgriffith commented on Feb 1, 2021

    @cdgriffith

    Thanks for the link, will watch that one! UPX is not a make or break deal for me, but I am happy to help test my code with any changes around it.

    For this ticket probably prudent to see if @MyDataIsReady responds soon, otherwise good to close from my point of view.

  6. MyDataIsReady commented on Feb 1, 2021

    @MyDataIsReady
    Author

    Seems to be working! Just tried with Windows 10 x64, Python 3.8.7 and Pyinstaller 4.2.

    Thanks!

  7. bwoodsend commented on Feb 2, 2021

    @bwoodsend
    Member

    I'm just writing this so that this issue doesn't get buried (again). To properly fix this we need either of Rok's solutions (preferably the second IMO) or for the UPX issue to be fixed their end.

  8. added 2 commits that reference this issue on Jun 2, 2021
    1ce168d
    c409987
  9. added a commit that references this issue on Jun 3, 2021
    71114c4
  10. henzef commented on Jun 26, 2021

    @henzef

    I had to exclude the following as well when using 32 bit python:

    exe = EXE(...,
              upx_exclude=["pyside2.abi3.dll",
                           "qtcore.pyd", "qtgui.pyd", "qtwidgets.pyd",
                           "qt5core.dll", "qt5gui.dll", "qt5svg.dll", "qt5widgets.dll", "qt5xml.dll"])
    

    Would it be possible to detect these automatically as well @rokm?

  11. rokm commented on Jun 27, 2021

    @rokm
    Member

    I had to exclude the following as well when using 32 bit python:

    exe = EXE(...,
              upx_exclude=["pyside2.abi3.dll",
                           "qtcore.pyd", "qtgui.pyd", "qtwidgets.pyd",
                           "qt5core.dll", "qt5gui.dll", "qt5svg.dll", "qt5widgets.dll", "qt5xml.dll"])
    

    Would it be possible to detect these automatically as well @rokm?

    Unfortunately, I don't think so. The automatic exclusion we have so far is based on characteristics that are known to break with UPX (i.e., CFG being enabled on a DLL, or a DLL being a Qt plugin). This does not seem to be the case with 32-bit Qt5 DLLs (and python extensions), so the only thing we could possibly do is automatically exclude everything that comes from PyQt5 or PySide2 folders (and their Qt6 equivalents) on 32-bit Windows/python.

    Is the failure mode for this specific case known? I.e., is it documented anywhere why 32-bit Qt5 DLLs are problematic when used with upx?

  12. henzef commented on Jun 28, 2021

    @henzef

    Is the failure mode for this specific case known? I.e., is it documented anywhere why 32-bit Qt5 DLLs are problematic when used with upx?

    No, I just found this out by excluding all pyside dlls and then replacing them one after the other with the UPX packed ones. I don't know if 32 bit builds are worth to invest time in if you don't see a low-hanging fruit immediately .
    Also note how I didn't have to exclude qtsvg.pyd or qtxml.pyd, I wonder what makes these different ...

  13. rokm commented on Jun 28, 2021

    @rokm
    Member

    Also note how I didn't have to exclude qtsvg.pyd or qtxml.pyd, I wonder what makes these different ...

    Do you really have to exclude qtcore.pyd, qtgui.py, and qtwidgets.pyd, though?

  14. henzef commented on Jun 28, 2021

    @henzef

    yes

  15. locked as resolved and limited conversation to collaborators on Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions