57 Commits

Author SHA1 Message Date
Mirco Miranda
fbf60f8bbb xcf: fix possible overflow
Port to KF6 of MR !187
2023-09-05 11:32:32 +00:00
Mirco Miranda
c11c5eff4f xcf: format v12 support
This is a patch over MR !108 by @sandsmark. Martin has done a great job implementing support and I find it a shame not to use it.

I made sure that the results are the same as the current version and fixed the problems of pixels with wrong colors with color depth grater than 8 bits. I also fixed conversion errors on mask and gray images (16/32 bits).
Unfortunately the internal rendering engine of the original code is 8-bit so I always forced the output of 8-bit images to correct the problems (see image below). Since it is a plugin with a "rendering engine", the tests to seriously validate it are potentially endless (as the original version is not perfect).

Errors of the original version of the MR (right) which should no longer occur:
![image](/uploads/9ef24eb5436bd19ff1fb428242a9c119/image.png)
2023-08-28 17:27:08 +00:00
Friedrich W. H. Kossebau
34ed3bad27 Add explicit moc includes to sources for moc-covered headers
* speeds up incremental builds as changes to a header will not always
  need the full mocs_compilation.cpp for all the target's headers rebuild,
  while having a moc file sourced into a source file only adds minor
  extra costs, due to small own code and the used headers usually
  already covered by the source file, being for the same class/struct
* seems to not slow down clean builds, due to empty mocs_compilation.cpp
  resulting in those quickly processed, while the minor extra cost of the
  sourced moc files does not outweigh that in summary.
  Measured times actually improved by some percent points.
  (ideally CMake would just skip empty mocs_compilation.cpp & its object
  file one day)
* enables compiler to see all methods of a class in same compilation unit
  to do some sanity checks
* potentially more inlining in general, due to more in the compilation unit
* allows to keep using more forward declarations in the header, as with the
  moc code being sourced into the cpp file there definitions can be ensured
  and often are already for the needs of the normal class methods
2023-07-02 03:08:44 +02:00
Volker Krause
4451737d2f Remove Qt 5 support 2023-01-24 17:15:14 +01:00
Mirco Miranda
c96ad6ba8a Fixes for sequential devices 2022-10-02 06:01:23 +00:00
Friedrich W. H. Kossebau
72a1cc23b1 Use consistently std::as_const instead of qAsConst
NO_CHANGELOG
2022-09-22 15:59:15 +02:00
Mirco Miranda
21928300c6 Enables opening of XCF files with Width and/or Height greater than 32K 2022-09-13 17:57:57 +00:00
Mirco Miranda
feb6d9b20f Fix image allocation with Qt 6
To make the plugins fail to allocate if the image size is greater than QImageReader::allocationLimit() it is necessary to allocate the image with QImageIOHandler::allocateImage().

Note that not all plugins have been changed and some others are not tested in the CI (maybe due to missing libraries).

PS: the following message is printed by QImageIOHandler::allocateImage() if the size is exceeded: "qt.gui.imageio: QImageIOHandler: Rejecting image as it exceeds the current allocation limit of XXX megabytes"
2022-09-07 14:03:33 +00:00
Laurent Montel
de320447f6 Remove extra ';' 2022-06-22 19:52:13 +02:00
Mirco Miranda
cff2604cf9 XCF: Support to QImageIOHandler::Size option 2022-04-29 13:23:20 +00:00
Mirco Miranda
3e751dd80d Fix XCF parasites metadata in QImage and support to ICC profile
- Fix parasite "gimp-comment" not set due to null QImage
- Support to parasite "icc-profile" using Qt 5.14+ API
- Added parasite "gimp-image-metadata" as QImage metadata "XML:org.gimp.xml"
- Added a XCF with XML metadata and icc prifile embedded in autotest folder (generated by GIMP 2.10.30)
- Tested with Qt 5.15.2 and Qt 6.2.3 under Windows and Qt 6.2.3 under macOS
2022-03-23 23:34:33 +00:00
Ahmad Samir
f5d574b3ad clang-tidy: one declaration per line; braces around statements
clang-tidy checks:
readability-isolate-declaration and readability-braces-around-statements

KF task: https://phabricator.kde.org/T14729

GIT_SILENT
2021-08-13 15:13:21 +02:00
Albert Astals Cid
ff53d3d7e9 xcf: Make sure offsets are not negative
It's not a huge problem since QIODevice::seek() is a noop on negative values but it's
just better to bail out as soon as possible when we realize the file is
broken
2021-05-05 17:23:59 +02:00
Albert Astals Cid
297ed9a2fe xcf: Fix Stack-buffer-overflow WRITE on broken files
oss-fuzz/33742
2021-05-02 09:50:50 +00:00
David Faure
95a19a15c3 xcf: fix new[]/delete mismatch, as detected by ASAN 2021-04-04 17:30:52 +02:00
Ahmad Samir
1169859b07 Run clang-format on all cpp/h files
NO_CHANGELOG
2021-03-08 20:15:33 +02:00
Ahmad Samir
e3ab850712 Add a trailing comma to enum
Should help produce better diffs and clang-format won't squash the enum
on one line.

GIT_SILENT
2021-03-08 20:14:42 +02:00
Andreas Cord-Landwehr
f4281984c1 Adapt license to LGPL-2.0-or-later
According to relicensecheck Brad is OK with changing LGPLv2 to LGPLv2+,
which is required to be compatible with the LGPL-2.1-or-later licensed
source files.
2020-07-21 09:26:47 +00:00
Friedrich W. H. Kossebau
9a04f2637f Use KF-standardized Qt logging categories
See https://community.kde.org/Frameworks/Frameworks_Logging_Policy
2020-07-13 04:01:44 +02:00
Martin T. H. Sandsmark
497b6b81bd Fix build on Windows.
We added our own implementation of rand_r to make sure we use the same
as Gimp, and to make Windows work. But we need to actually use it
everywhere.

Discussion in Differential:

Differential Revision: https://phabricator.kde.org/D25267
2020-04-15 09:46:54 +02:00
Martin T. H. Sandsmark
c60e77c048 Add support for modern Gimp images/XCF files
We now support up to and including version 11 of the XCF format, earlier
it only supported version 1 (from 1997, according to the XCF spec).

Biggest difference seems to be that they changed to 64bit for offsets
from version 11 and upwards, otherwise it's mostly just newer enum
values and theoretically major stuff that we don't really need to care
about to get a thumbnail (e. g. linear vs. perceptual RGB).

We still don't support all features, but now it handles that more
gracefully and should at least create thumbnails that are usable. It
should also be easier to update in the future if/when there comes new
versions.

Also added a test file created with the latest version of Gimp
(2.10.18).

Reviewed By: aacid

Differential Revision: https://phabricator.kde.org/D25937
2020-04-13 14:52:33 +02:00
Albert Astals Cid
5c4c05257c xcf: Fix regression when reading files with "unsupported" properties
Summary:
The fact that we don't know the property is most of the times not fatal,
so what we have to do is just "skip" the property and hope for the best

BUGS: 411327

Reviewers: cfeck, apol, vkrause

Reviewed By: vkrause

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D24114
2019-09-20 22:41:26 +02:00
Albert Astals Cid
7afaacb093 xcf: Properly read image resolution
Summary:
QDataStream reads 64 bits when reading into a float unless you tell it to use SinglePrecision,
since floats in xcf are 32 bit, do that

Reviewers: cfeck, apol, vkrause

Reviewed By: vkrause

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D24113
2019-09-20 22:41:03 +02:00
Albert Astals Cid
6fea48c4ee xcf: Fix uninitialized memory use on broken documents
oss-fuzz #14312
2019-04-17 20:09:49 +02:00
Albert Astals Cid
aaa285a3b9 xcf: layer is const in copy and merge, mark it as such 2019-04-17 17:37:28 +02:00
Albert Astals Cid
35e64c44d8 No & is a bit faster here 2019-04-17 17:37:28 +02:00
Albert Astals Cid
bd704045e6 xcf: Don't crash with files with unsupported layer modes 2019-03-31 01:35:33 +01:00
Albert Astals Cid
aeec934839 xcf: Fix uninitialized memory use on broken documents
oss-fuzz/12871
2019-02-08 23:27:03 +01:00
Albert Astals Cid
0c4f2f8e62 add const, helps understand the function better 2019-02-08 23:07:56 +01:00
Albert Astals Cid
bad90cea4b xcf: Don't divide by 0
oss-fuzz/12815
2019-02-03 14:06:33 +01:00
Albert Astals Cid
8d0b625538 xcf: Fix fix for opacity being out of bounds
If max opacity is 255 we want the min between opacity and 255 and not the max
2019-02-01 11:30:28 +01:00
Albert Astals Cid
e7f3c0be44 max opacity is 255
Fixes oss-fuzz/12782
2019-01-31 01:25:38 +01:00
Albert Astals Cid
c3152506e2 xcf: Fix assert in files with two PROP_COLORMAP
It's most probably a broken file but better if we don't assert ^_^

oss-fuzz/12780
2019-01-31 01:19:52 +01:00
Albert Astals Cid
4ee92527c4 xcf: Implement robustness for when PROP_APPLY_MASK is not on the file
fixes oss-fuzz/12754
2019-01-29 22:34:04 +01:00
Albert Astals Cid
1bad780baa xcf: loadHierarchy: Obey the layer.type and not the bpp
Otherwise we end up doing uninitialized memory reads on broken/fuzzed
files

oss-fuzz/12761
2019-01-29 20:36:15 +01:00
Albert Astals Cid
f61d64e0e5 xcf: Initialize x/y_offset
https://gitlab.gnome.org/GNOME/gimp/raw/master/devel-docs/xcf.txt
  When reading old XCF files that lack this property, assume (0,0).
2019-01-28 21:51:10 +01:00
Albert Astals Cid
188271a5d0 xcf: initialize layer mode
https://gitlab.gnome.org/GNOME/gimp/raw/master/devel-docs/xcf.txt
  When reading old XCF files that lack this property, assume mode==0.
2019-01-28 21:05:29 +01:00
Albert Astals Cid
311296dd19 xcf: initialize layer opacity
https://gitlab.gnome.org/GNOME/gimp/raw/master/devel-docs/xcf.txt
  When reading old XCF files that lack this property, full opacity
  should be assumed.
2019-01-28 20:31:18 +01:00
Albert Astals Cid
d6ae11a691 xcf: set buffer to 0 if read less data that expected
Fixes MemorySanitizer: use-of-uninitialized-value on fuzzed file
2019-01-28 20:09:21 +01:00
Albert Astals Cid
3923c9b855 bzero -> memset
Seems bzero is less portable
2019-01-28 19:18:01 +01:00
Fabian Vogt
51d710adda Fix various OOB reads and writes in kimg_tga and kimg_xcf
Summary:
I had a look at some image loading code in kimageformats and found memory
corruption bugs (there might be more):

- oobwrite4b.xcf: OOB write in kimg_xcf:

By overflowing the "size = 3 * ncolors + 4;" calculation, it's possible to make
size == 3 or size == 0, which then allows 1 or 4 bytes to be overwritten:
https://cgit.kde.org/kimageformats.git/tree/src/imageformats/xcf.cpp?id=3f2552f21b1cdef063c2a93cc95d42a8cf907fcf#n484
The values aren't arbitrary, so AFAICT DoS only.
Fix is to move the sanity check for size below the assignment.

- oobread.tga: OOB read in kimg_tga:

By overflowing the "size = tga.width * tga.height * pixel_size" calculation,
it's possible to cause OOB reads later on as the image data array is too small:
https://cgit.kde.org/kimageformats.git/tree/src/imageformats/tga.cpp?id=3f2552f21b1cdef063c2a93cc95d42a8cf907fcf#n192
Fix is to use a 64bit integer instead.

- oobwrite4b.tga/oobwrite507.tga: OOB write in kimg_tga

If RLE is enabled, any size checks are skipped, so it's possible to write
either 128 repetitions of an arbitrary four byte value (oobwrite4b.tga)
or or 507 arbitrary bytes (oobwrite507.tga) out of bounds.
https://cgit.kde.org/kimageformats.git/tree/src/imageformats/tga.cpp?id=3f2552f21b1cdef063c2a93cc95d42a8cf907fcf#n209
Fix is to check for "num" being negative before reading into the buffer.

Also, bail out early if there is no more data available (reading a 65kx65k px image from 14B data takes ages otherwise)

Test Plan:
Stopped crashing and valgrind don't complain anymore.

TGA preview still works for valid files.

Reviewers: aacid

Reviewed By: aacid

Subscribers: lbeltrame, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D18574
2019-01-28 14:21:27 +01:00
Albert Astals Cid
309cddbe83 xcf: bzero buffer if read less data than expected 2019-01-28 01:30:17 +01:00
Albert Astals Cid
47f46d4463 xcf: Only call setDotsPerMeterX/Y if PROP_RESOLUTION is found
https://gitlab.gnome.org/GNOME/gimp/blob/master/devel-docs/xcf.txt says
it's not really that important to be there
2019-01-27 13:14:30 +01:00
Albert Astals Cid
bff6142b44 xcf: initialize num_colors 2019-01-27 13:07:37 +01:00
Albert Astals Cid
09abfd8084 xcf: Initialize layer visible property
https://gitlab.gnome.org/GNOME/gimp/blob/master/devel-docs/xcf.txt says
	When reading old XCF files that lack this property, assume that layers are visible
2019-01-27 13:03:51 +01:00
Albert Astals Cid
964624ba40 xcf: Don't cast int to enum that can't hold that int value 2019-01-27 12:50:19 +01:00
Albert Astals Cid
3dee6f7c47 xcf: Do not overflow int on the setDotsPerMeterX/Y call 2019-01-27 12:29:07 +01:00
Albert Astals Cid
b8cb5e322c delete copy constructor and assignment operator of some internal classes
they are unused, but if anyone would use them things would go wrong, so protect us from it
2019-01-13 22:30:55 +01:00
Christoph Feck
19f33239e7 [XCF/GIMP loader] Raise maximimum allowed image size to 32767x32767 on 64 bit platforms
The GIMP image loader had a limit to 16K x 16K pixels, because this would
already exhaust the 2 GByte address space limit of 32 bit systems.

Remove this limit on 64 bit systems to allow the full 32K x 32K size.

BUG: 391970

Differential Revision: https://phabricator.kde.org/D12557
2018-05-02 02:10:26 +02:00
Laurent Montel
698ba297d3 We depend against 5.8.0 now 2018-03-27 08:01:04 +02:00