nomacs icon indicating copy to clipboard operation
nomacs copied to clipboard

Qt Jpeg2000 plugin crashes nomacs

Open scrubbbbs opened this issue 8 months ago • 7 comments

This plugin is disabled in most systems, but it was enabled currently in homebrew/qt6 package. Since we also have this in kimageformats this isn't really a problem but I thought I'd make a record of it for jasper/homebrew.

Analysis: Seems to be problem with threading, will occur most often when viewing thumbnails (shift+T) as we use threads there.

Test files: formats_testset/JPEG2000

Qt version: 6.8.2

homebrew info (JasPer package)

==> jasper: stable 4.2.5 (bottled)
Library for manipulating JPEG-2000 images
https://ece.engr.uvic.ca/~frodo/jasper/
Installed
/usr/local/Cellar/jasper/4.2.5 (45 files, 1.5MB) *
  Poured from bottle using the formulae.brew.sh API on 2025-03-31 at 03:03:22
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/j/jasper.rb
License: JasPer-2.0
==> Dependencies
Build: cmake ✘
Required: jpeg-turbo ✔
==> Analytics
install: 42,554 (30 days), 89,340 (90 days), 461,208 (365 days)
install-on-request: 1,800 (30 days), 3,041 (90 days), 22,242 (365 days)
build-error: 0 (30 days)

stack trace

2025-04-03 08:10:31.407804-0700 nomacs[91637:466186] [Loader] butterfly.jpf seems to have the wrong extension, the content type is image/jp2
2025-04-03 08:10:31.407934-0700 nomacs[91637:466186] [Loader::qt-unknown-suffix] butterfly.jpf "image/jp2" QImage::Format_RGB32 "" transform:none 830ms
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
warning: skipping unknown tag type
FATAL ERROR: jas_cleanup_library called with active JasPer threads
Process 91637 stopped
* thread #11, name = 'Thread (pooled)', stop reason = signal SIGABRT
    frame #0: 0x00007ff808a64196 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`:
->  0x7ff808a64196 <+10>: jae    0x7ff808a641a0            ; <+20>
    0x7ff808a64198 <+12>: movq   %rax, %rdi
    0x7ff808a6419b <+15>: jmp    0x7ff808a5dc7b            ; cerror_nocancel
    0x7ff808a641a0 <+20>: retq   
Target 0: (nomacs) stopped.
(lldb) bt
* thread #11, name = 'Thread (pooled)', stop reason = signal SIGABRT
  * frame #0: 0x00007ff808a64196 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007ff808a9bee6 libsystem_pthread.dylib`pthread_kill + 263
    frame #2: 0x00007ff8089c2b45 libsystem_c.dylib`abort + 123
    frame #3: 0x0000000100cc2412 libjasper.7.dylib`jas_cleanup_library.cold.2 + 23
    frame #4: 0x0000000100c9e9f4 libjasper.7.dylib`jas_cleanup_library + 125
    frame #5: 0x0000000155e128d6 libqjp2.dylib`Jpeg2000JasperReader::~Jpeg2000JasperReader() + 98
    frame #6: 0x0000000155e11a26 libqjp2.dylib`QJp2Handler::read(QImage*) + 144
    frame #7: 0x0000000104dd3881 QtGui`QImageReader::read(QImage*) + 881

scrubbbbs avatar Apr 03 '25 15:04 scrubbbbs

You can simply delete the libqjp2.dylib

novomesk avatar Apr 03 '25 19:04 novomesk

You can simply delete the libqjp2.dylib

I added a check and this suggestion in macos cmake.

scrubbbbs avatar Apr 03 '25 19:04 scrubbbbs

It would be good to make a simple demonstration program, which opens JP2 file in threads and to report to Qt.

Older Qt5 versions of nomacs had this plug-in, interesting, that we did not observe the crash. Maybe it was because JP2 images were rarely used.

novomesk avatar Apr 04 '25 06:04 novomesk

I can't reproduce this on a real Mac. Also I renamed to a wrong extension .jpf instead of .jp2

[Warning] [Loader] DSC_1211.jpf seems to have the wrong extension, the content type is image/jp2
[Loader::qt-unknown-suffix] DSC_1211.jpf "image/jp2" QImage::Format_RGB32 "" transform:none 222ms
[Thumbnail] DSC_1211.jpf exif=no size=858x1086 scaled=316x400 223ms
> brew info jasper
Warning: Treating jasper as a formula. For the cask, use homebrew/cask/jasper or specify the `--cask` flag. To silence this message, use the `--formula` flag.
==> jasper: stable 4.2.5 (bottled)
Library for manipulating JPEG-2000 images
https://ece.engr.uvic.ca/~frodo/jasper/
Installed
/usr/local/Cellar/jasper/4.2.5 (45 files, 1.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2025-04-02 at 21:51:59
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/j/jasper.rb
License: JasPer-2.0
==> Dependencies
Build: cmake ✔
Required: jpeg-turbo ✔
> brew info qt
==> qt: stable 6.8.2 (bottled), HEAD
Cross-platform application and UI framework
https://www.qt.io/
Installed
/usr/local/Cellar/qt/6.8.2_1 (16,855 files, 730MB) *
  Poured from bottle using the formulae.brew.sh API on 2025-04-02 at 21:52:10
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/q/qt.rb
License: BSD-3-Clause AND GFDL-1.3-no-invariants-only AND GPL-2.0-only AND (GPL-3.0-only WITH Qt-GPL-exception-1.0) AND LGPL-3.0-only
==> Dependencies
Build: cmake ✔, ninja ✘, node ✔, pkgconf ✔, [email protected] ✔, vulkan-headers ✘, vulkan-loader ✘, molten-vk ✘
Required: assimp ✔, brotli ✔, dbus ✔, double-conversion ✔, freetype ✔, glib ✔, harfbuzz ✔, hunspell ✔, icu4c@77 ✔, jasper ✔, jpeg-turbo ✔, libb2 ✔, libmng ✔, libpng ✔, libtiff ✔, md4c ✔, openssl@3 ✔, pcre2 ✔, sqlite ✔, webp ✔, zstd ✔
==> Requirements
Build: macOS <= 14 (or Linux) ✘, Xcode (on macOS) ✔
> brew config
HOMEBREW_VERSION: 4.4.27
ORIGIN: https://github.com/Homebrew/brew
HEAD: 9b1efcd944408db0bd85f82fe4724ccae04a812f
Last commit: 4 days ago
Branch: stable
Core tap JSON: 02 Apr 20:04 UTC
Core cask tap JSON: 02 Apr 20:04 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: :0.0
HOMEBREW_EDITOR: /usr/bin/vi
HOMEBREW_MAKE_JOBS: 16
Homebrew Ruby: 3.3.7 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.3.7/bin/ruby
CPU: 16-core 64-bit kabylake
Clang: 17.0.0 build 1700
Git: 2.49.0 => /usr/local/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.4-x86_64
CLT: 16.3.0.0.1.1742442376
Xcode: 16.3
nomacs 3.21.0, x86_64
6a2e85b8, 2025-04-03

macOS Sequoia (15.4), 0GB
Qt 6.8.2, cocoa, scale=2.00
Exiv2 0.28.5
LibRAW 0.21.3-Release
OpenCV 4.11.0
TIFF 4.7.0
QuaZip v1

hmueller01 avatar Apr 04 '25 12:04 hmueller01

Thanks for the update, this could be down to a difference in configurations. While our package versions match, they probably used different compiler versions. The virtual CPU config for OpenCore is a bit weird to get osx to work, maybe jasper relies on a CPU feature the vm has disabled. I'll report back if/when I can create a canonical test program/file set.

scrubbbbs avatar Apr 04 '25 13:04 scrubbbbs

Or maybe it's a problem with the file. I created that JPEG-2000 file on the Mac from a jpg using Preview as I did not have any JPEG-2000 files (as @novomesk said, very rarely used file format).

hmueller01 avatar Apr 04 '25 13:04 hmueller01

I'm seeing a similar crash in libjasper when testing the Linux AppImage built on neon/22.04. I know this distro is outdated now but it points to something that is not macOS-related. Though it could be my hardware because both crashes occur in virtual machines.

scrubbbbs avatar Nov 05 '25 12:11 scrubbbbs