artemsen / swayimg

Image viewer for Wayland
MIT License
348 stars 27 forks source link

Segfault upon opening any image #167

Closed fosskers closed 3 weeks ago

fosskers commented 1 month ago

I have swayimg built from master, but it currently segfaults when attempting to open any image. For errors, I've seen:

munmap_chunk(): invalid pointer
fish: Job 1, 'swayimg underprovisioned.png' terminated by signal SIGABRT (Abort)

but also occasionally a message about a "corrupted doubly-linked list". Any idea what's going on? Thank you.

For reference:

artemsen commented 1 month ago

Looks like a bug, but I can't reproduce it. Do you have a custom config file for swayimg?

fosskers commented 1 month ago

Thanks for checking.

Do you have a custom config file for swayimg?

Nothing under ~/.config/ that I can see.

Note also that this spontaneously started happening. Until a few days ago I had no issues, which makes me think that something that swayimg links to might have changed. It's happening on both my machines.

fosskers commented 1 month ago

This may be too large to be useful, but...

> ldd /bin/swayimg
        linux-vdso.so.1 (0x0000757ca4ac0000)
        libwayland-client.so.0 => /usr/lib/libwayland-client.so.0 (0x0000757ca4a63000)
        libjson-c.so.5 => /usr/lib/libjson-c.so.5 (0x0000757ca4a4f000)
        libxkbcommon.so.0 => /usr/lib/libxkbcommon.so.0 (0x0000757ca4a07000)
        libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x0000757ca49b7000)
        libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x0000757ca48ee000)
        libexif.so.12 => /usr/lib/libexif.so.12 (0x0000757ca48af000)
        libOpenEXRCore-3_2.so.31 => /usr/lib/libOpenEXRCore-3_2.so.31 (0x0000757ca4600000)
        libgif.so.7 => /usr/lib/libgif.so.7 (0x0000757ca48a2000)
        libheif.so.1 => /usr/lib/libheif.so.1 (0x0000757ca452b000)
        libavif.so.16 => /usr/lib/libavif.so.16 (0x0000757ca4871000)
        libjpeg.so.8 => /usr/lib/libjpeg.so.8 (0x0000757ca448f000)
        libjxl.so.0.10 => /usr/lib/libjxl.so.0.10 (0x0000757ca4000000)
        libpng16.so.16 => /usr/lib/libpng16.so.16 (0x0000757ca4835000)
        librsvg-2.so.2 => /usr/lib/librsvg-2.so.2 (0x0000757ca3a00000)
        libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x0000757ca4430000)
        libcairo.so.2 => /usr/lib/libcairo.so.2 (0x0000757ca42fd000)
        libtiff.so.6 => /usr/lib/libtiff.so.6 (0x0000757ca3f75000)
        libwebp.so.7 => /usr/lib/libwebp.so.7 (0x0000757ca3991000)
        libwebpdemux.so.2 => /usr/lib/libwebpdemux.so.2 (0x0000757ca482d000)
        libc.so.6 => /usr/lib/libc.so.6 (0x0000757ca37a0000)
        libffi.so.8 => /usr/lib/libffi.so.8 (0x0000757ca42f2000)
        /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x0000757ca4ac2000)
        libexpat.so.1 => /usr/lib/libexpat.so.1 (0x0000757ca42c9000)
        libz.so.1 => /usr/lib/libz.so.1 (0x0000757ca42b0000)
        libbz2.so.1.0 => /usr/lib/libbz2.so.1.0 (0x0000757ca3f62000)
        libharfbuzz.so.0 => /usr/lib/libharfbuzz.so.0 (0x0000757ca3686000)
        libbrotlidec.so.1 => /usr/lib/libbrotlidec.so.1 (0x0000757ca3f53000)
        libm.so.6 => /usr/lib/libm.so.6 (0x0000757ca3597000)
        libdeflate.so.0 => /usr/lib/libdeflate.so.0 (0x0000757ca3f3d000)
        libx265.so.209 => /usr/lib/libx265.so.209 (0x0000757ca2200000)
        libde265.so.0 => /usr/lib/libde265.so.0 (0x0000757ca3514000)
        libaom.so.3 => /usr/lib/libaom.so.3 (0x0000757ca1800000)
        libsharpyuv.so.0 => /usr/lib/libsharpyuv.so.0 (0x0000757ca42a3000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0000757ca1400000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x0000757ca21d2000)
        libyuv.so => /usr/lib/libyuv.so (0x0000757ca212c000)
        libdav1d.so.7 => /usr/lib/libdav1d.so.7 (0x0000757ca1221000)
        librav1e.so.0.7 => /usr/lib/librav1e.so.0.7 (0x0000757ca0e00000)
        libSvtAv1Enc.so.2 => /usr/lib/libSvtAv1Enc.so.2 (0x0000757c98600000)
        libjxl_cms.so.0.10 => /usr/lib/libjxl_cms.so.0.10 (0x0000757ca20f6000)
        libhwy.so.1 => /usr/lib/libhwy.so.1 (0x0000757ca3f31000)
        libbrotlienc.so.1 => /usr/lib/libbrotlienc.so.1 (0x0000757ca174e000)
        libcairo-gobject.so.2 => /usr/lib/libcairo-gobject.so.2 (0x0000757ca3f26000)
        libgdk_pixbuf-2.0.so.0 => /usr/lib/libgdk_pixbuf-2.0.so.0 (0x0000757ca20b2000)
        libgio-2.0.so.0 => /usr/lib/libgio-2.0.so.0 (0x0000757c98433000)
        libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x0000757ca0cb2000)
        libxml2.so.2 => /usr/lib/libxml2.so.2 (0x0000757c982e7000)
        libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0x0000757ca3504000)
        libpango-1.0.so.0 => /usr/lib/libpango-1.0.so.0 (0x0000757ca16e5000)
        libX11.so.6 => /usr/lib/libX11.so.6 (0x0000757c981a9000)
        libXext.so.6 => /usr/lib/libXext.so.6 (0x0000757ca209d000)
        libXrender.so.1 => /usr/lib/libXrender.so.1 (0x0000757ca34f8000)
        libxcb.so.1 => /usr/lib/libxcb.so.1 (0x0000757ca16ba000)
        libxcb-render.so.0 => /usr/lib/libxcb-render.so.0 (0x0000757ca208e000)
        libxcb-shm.so.0 => /usr/lib/libxcb-shm.so.0 (0x0000757ca34f3000)
        libpixman-1.so.0 => /usr/lib/libpixman-1.so.0 (0x0000757ca1177000)
        libzstd.so.1 => /usr/lib/libzstd.so.1 (0x0000757c980ca000)
        liblzma.so.5 => /usr/lib/liblzma.so.5 (0x0000757ca1687000)
        libjbig.so.2.1 => /usr/lib/libjbig.so.2.1 (0x0000757ca2080000)
        libgraphite2.so.3 => /usr/lib/libgraphite2.so.3 (0x0000757ca1155000)
        libbrotlicommon.so.1 => /usr/lib/libbrotlicommon.so.1 (0x0000757ca1132000)
        libmvec.so.1 => /usr/lib/libmvec.so.1 (0x0000757c97fd2000)
        libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x0000757ca2079000)
        libmount.so.1 => /usr/lib/libmount.so.1 (0x0000757ca0c63000)
        libpcre2-8.so.0 => /usr/lib/libpcre2-8.so.0 (0x0000757c97f33000)
        libicuuc.so.75 => /usr/lib/libicuuc.so.75 (0x0000757c97d39000)
        libpangoft2-1.0.so.0 => /usr/lib/libpangoft2-1.0.so.0 (0x0000757ca0c47000)
        libfribidi.so.0 => /usr/lib/libfribidi.so.0 (0x0000757c97d19000)
        libthai.so.0 => /usr/lib/libthai.so.0 (0x0000757ca1125000)
        libXau.so.6 => /usr/lib/libXau.so.6 (0x0000757ca1120000)
        libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x0000757ca0c3f000)
        libblkid.so.1 => /usr/lib/libblkid.so.1 (0x0000757c97ce0000)
        libicudata.so.75 => /usr/lib/libicudata.so.75 (0x0000757c95e00000)
        libdatrie.so.1 => /usr/lib/libdatrie.so.1 (0x0000757c97cd7000)
fosskers commented 1 month ago

I attempted valgrind but I'm not positive what it's displeased of:

> valgrind swayimg alpine.png
==94251== Memcheck, a memory error detector
==94251== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==94251== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==94251== Command: swayimg alpine.png
==94251== 

valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:  
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strcmp
valgrind:  in an object with soname matching:   ld-linux-x86-64.so.2
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux-x86-64.so.2
valgrind:  
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.  The package you need
valgrind:  to install for fix (1) is called
valgrind:  
valgrind:    On Debian, Ubuntu:                 libc6-dbg
valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo
valgrind:  
valgrind:  Note that if you are debugging a 32 bit process on a
valgrind:  64 bit system, you will need a corresponding 32 bit debuginfo
valgrind:  package (e.g. libc6-dbg:i386).
valgrind:  
valgrind:  Cannot continue -- exiting now.  Sorry.
artemsen commented 1 month ago

Until a few days ago I had no issues

Swayimg in master is under development, so it might be my bug =) Does the latest release version (2.5) work?

I attempted valgrind but I'm not positive what it's displeased of

I think valgrind wants debug symbols for libc.

I still can't understand where the bug.

  1. Please, try to run swayimg without Sway integration: SWAYSOCK=/dev/null swayimg image.png
  2. Attach your binary file swayimg to this issue, I will try it on my machine.
  3. Try to start it in gdb: gsb --args swayimg image.png and then run in gdb console. Gdb will stop on error, the command bt will show backtrace, attach it to the issue, please.
fosskers commented 1 month ago

Sorry I should have mentioned that this was occuring with a stable version as well, and I moved to master to see if anything changed, and it didn't. That's what makes me think that something fishy is happening with a dependency.

I'll try your other suggestions now.

UPDATE: Still getting invalid pointer with the disabled SWAYSOCK, for both 2.5 and master.

UPDATE: Firefox isn't letting me select a file in /usr/bin/ to upload.

fosskers commented 1 month ago

gdb

The gdb window itself also entirely freezes after the abort. It won't respond to normal window-close commands (through sway) so I need to kill it through the terminal.

artemsen commented 1 month ago

The gdb window itself also entirely freezes after the abort

It doesn't freeze. It is because swayimg creates a window, which is transparent at the start. You can disable Sway integration to prevents this (just export SWAYSOCK=/dev/null before running gdb). Also, you can build swayimg in debug mode (meson setup --buildtype=debug ...), this will allow to get detailed information about the error.

UPDATE: Firefox isn't letting me select a file in /usr/bin/ to upload.

Try

cd ~/Downloads
tar czf swayimg.tar.gz /usr/bin/swayimg

and then upload the result archive.

appashchenko commented 1 month ago

Until a few days ago I had no issues

Did you update your wlroots or sway recently? I mean pull and build. Regressions and breaking changes from there are common.

swayimg:master works fine with sway-1.9 wlroots-0.17.4

fosskers commented 1 month ago

Screensharing was breaking for me in certain applications (assuming due to the down-pinned wlroots), so this week I moved to sway-git to fix that, which worked. I will try to downgrade to normal sway to see if swayimg gets cured.

kindergartener commented 3 weeks ago

I fixed this issue by changing the default font. I found that there was no default config file and after creating one myself I still encountered the issue. I printed out the font name swayimg was trying to load and found "NimbusMonoPS-Regular.otf". I changed the font to another monospace font and it worked.

This is where the segfault happened for me: font.c:217 I compiled swayimg with freetype2 release 2.13.0

artemsen commented 3 weeks ago

Thank you! Yes, this is definitely a bug that pops up when encountering certain fonts.