[graphics/krita] libs/pigment: Fix UB in KoColorProfileQuery

Wolthera van Hövell <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit d2b9b475fea28cb5985dac586d1f3c61c5c48269 by Wolthera van Hövell, on behalf of Dmitry Kazakov.
Committed on 16/07/2026 at 16:26.
Pushed by woltherav into branch 'master'.

Fix UB in KoColorProfileQuery

We cannot compare to KoColorimetryUtils::xy(),
because its members are not initialized, which
causes UB.

We cannot safely choose an "invalid" value for xy
in general, so we just explicitly initialize whitePoint
to {0,0} (which is invalid white point value) and then
compare against that.

M  +10   -4    libs/pigment/KoColorProfileQuery.h

https://invent.kde.org/graphics/krita/-/commit/d2b9b475fea28cb5985dac586d1f3c61c5c48269

diff --git a/libs/pigment/KoColorProfileQuery.h b/libs/pigment/KoColorProfileQuery.h
index 80acacd61b7..859faa5a85d 100644
--- a/libs/pigment/KoColorProfileQuery.h
+++ b/libs/pigment/KoColorProfileQuery.h
@@ -22,7 +22,13 @@ struct KoColorProfileQuery {
         , transfer(transfer)
     {}
 
-    KoColorimetryUtils::xy whitePoint; /// The desired white point of the profile.
+    KoColorProfileQuery(const KoColorProfileQuery &rhs) = default;
+    KoColorProfileQuery(KoColorProfileQuery &&rhs) = default;
+
+    KoColorProfileQuery& operator=(const KoColorProfileQuery&rhs) = default;
+    KoColorProfileQuery& operator=(KoColorProfileQuery &&rhs) = default;
+
+    KoColorimetryUtils::xy whitePoint {0.0, 0.0}; /// The desired white point of the profile.
     QList<KoColorimetryUtils::xy> rgbColorants; /// Rgb Primaries of the profile. When empty, this is a query for a greyscale profile.
 
     ColorPrimaries primaries; /// CICP-compatible enum value representing the white point and primaries.
@@ -38,13 +44,13 @@ struct KoColorProfileQuery {
         return transfer != TRC_UNSPECIFIED
             && rgbColorants.isEmpty()
             && primaries == PRIMARIES_UNSPECIFIED
-            && !(whitePoint == KoColorimetryUtils::xy());
+            && !(whitePoint == KoColorimetryUtils::xy{0.0, 0.0});
     }
 
     inline bool isRgb() const {
         return transfer != TRC_UNSPECIFIED
-            && (primaries != PRIMARIES_UNSPECIFIED || !rgbColorants.isEmpty())
-            && !(whitePoint == KoColorimetryUtils::xy());
+            && (primaries != PRIMARIES_UNSPECIFIED
+                || (!rgbColorants.isEmpty() && !(whitePoint == KoColorimetryUtils::xy{0.0, 0.0})));
     }
 
     inline bool operator==(const KoColorProfileQuery &rhs) const {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.