Bug 492503

Summary: Opening files >8192x8192 (>67108864 pixels overall) fails after latest update
Product: [Applications] kolourpaint Reporter: Alex <kdebugs>
Component: generalAssignee: kolourpaint-support
Status: RESOLVED FIXED    
Severity: major CC: justin, kdebugs
Priority: NOR    
Version First Reported In: 24.08.0   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Error shown when loading large file.

Description Alex 2024-09-01 16:12:50 UTC
Created attachment 173203 [details]
Error shown when loading large file.

SUMMARY
Opening files >8192x8192  (>67108864 pixels overall) fails after latest update.

STEPS TO REPRODUCE
1.  Open kolourpaint and goto "Image -> Resize/Scale".
2.  Click "Resize" and set height and width to 8193
3.  Save and close the file
4.  Try to open the file, you will see the error:   'Could not open "{$filename}" - unsupported image format.'
The file may be corrupt.

OBSERVED RESULT

Kolourpaint fails to load the file and renders a blank (white) cavas 2048x2048 pixels on starting.

EXPECTED RESULT

Kolourpaint loads and displays the file.

SOFTWARE/OS VERSIONS
OS: Fedora release 40 (Forty)
KDE Frameworks Version:  6.5.0
Qt Version: 6.7.2 (built against 6.7.2)

ADDITIONAL INFORMATION
Comment 1 Justin Zobel 2024-09-02 03:58:52 UTC
Confirmed on kolourpaint built from git master.
Comment 2 Justin Zobel 2024-09-02 04:06:19 UTC
Just started from konsole and got this which seems relevant:
qt.gui.imageio: QImageIOHandler: Rejecting image as it exceeds the current allocation limit of 256 megabytes
Comment 3 Alex 2024-09-02 11:25:18 UTC
So, seems like a workaround for this is to set the QT_IMAGEIO_MAXALLOC environment variable according to https://doc.qt.io/qt-6/qimagereader.html.  Doing:

$ export QT_IMAGEIO_MAXALLOC=8192
$ kolourpaint 

allows me to open large files again (8192MiB may be overkill for my needs currently, but you get the point you can define an arbitrary value).

Seems like the fix would be for  kolourpaint to set QImageReader::setAllocationLimit(0).

Amusingly, the preview that shows up in the File -> Open dialog works regardless of what limit is set, so maybe the above is already done for that.
Comment 4 Alex 2024-09-02 11:29:05 UTC
edit to my last comment:
$ export QT_IMAGEIO_MAXALLOC=0 

works also, I expect functionally the same as code doing QImageReader::setAllocationLimit(0)
Comment 5 Justin Zobel 2024-09-02 11:44:55 UTC
Thanks for the investigative work! Hopefully it should be an easy fix for the developers if the code already exists in the open dialog function!
Comment 6 Martin Koller 2024-09-25 12:04:46 UTC
Git commit 5c6f5b4d10065d136f733d8644be410854c13551 by Martin Koller.
Committed on 25/09/2024 at 12:03.
Pushed by mkoller into branch 'master'.

Unset memory limit for QImageReader

M  +1    -0    kolourpaint.cpp

https://invent.kde.org/graphics/kolourpaint/-/commit/5c6f5b4d10065d136f733d8644be410854c13551