https://bugs.kde.org/show_bug.cgi?id=529102
Bug ID: 529102
Summary: RegionF::united()/xored() never return when a
rectangle has a NaN coordinate (kwin_wayland grew to
67 GB and was OOM-killed)
Classification: Plasma
Product: kwin
Version First 6.7.6
Reported In:
Platform: Gentoo Packages
OS: Linux
Status: REPORTED
Severity: major
Priority: NOR
Component: core
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
SUMMARY
kwin_wayland's main thread got stuck appending to a QList<RectF>: within about
a minute it
used all 64 GB of RAM and 24 GB of swap. The session froze (no input, no
repaint), and the
kernel's OOM killer killed kwin_wayland with 52 GB resident and 15 GB in swap,
which ended
the Plasma session.
The likely cause is RegionF's scanline algorithms. RegionF::unite(),
subtract(), intersect()
and exclusiveOr() move to the next band only when
if (leftRect.bottom() == scanline) leftIndex = leftEnd;
if (rightRect.bottom() == scanline) rightIndex = rightEnd;
and xorBands() only when rect.right() == scanline. If a rectangle has a NaN
coordinate,
scanline can become NaN (std::min/std::max with a NaN operand), the comparison
is then always
false, neither index advances, and every pass appends another rectangle to
m_rects (in
xorBands() with a NaN x it loops without appending). A NaN top() also breaks
the band grouping
(left[leftIndex].top() == left[leftEnd].top() is false), which leaves an empty
span and
a null previousRect in mergeBands().
I could not find which code fed the NaN rectangle into RegionF. kwin_wayland
was SIGKILLed,
so there is no core dump, and the distribution's libkwin is stripped. The
reproducer below
shows the loop itself.
STEPS TO REPRODUCE
1. Save this as regionf-nan.cpp:
```cpp
// RegionF with a NaN coordinate. Each case runs one operation on two
// one-rectangle regions; only "finite" finishes.
#include "core/region.h"
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace KWin;
int main(int argc, char **argv)
{
const qreal nan = std::nan("");
const RegionF other(50, 20, 100, 100);
const char *c = argc > 1 ? argv[1] : "finite";
RegionF result;
if (!strcmp(c, "united-nan-height")) {
result = RegionF(0, 0, 100, nan).united(other); // endless loop,
allocates
} else if (!strcmp(c, "united-nan-y")) {
result = RegionF(0, nan, 100, 100).united(other); // SIGSEGV in
mergeBands()
} else if (!strcmp(c, "xored-nan-height")) {
result = RegionF(0, 0, 100, nan).xored(other); // endless loop,
allocates
} else if (!strcmp(c, "xored-nan-x")) {
result = RegionF(nan, 0, 100, 100).xored(other); // endless loop, no
allocation
} else {
result = RegionF(0, 0, 100, 100).united(other); // finishes, 3 rects
}
printf("%s: finished, %lld rects\n", c, (long long)result.rects().size());
return 0;
}
```
2. Build it against the installed libkwin.so.6, with the headers from the
matching KWin
6.7.6 source tree:
echo '#define KWIN_EXPORT' > kwin_export.h
g++ -std=c++20 -I. -I<kwin-6.7.6>/src $(pkg-config --cflags Qt6Core Qt6Gui)
\
regionf-nan.cpp -o regionf-nan /usr/lib64/libkwin.so.6 $(pkg-config
--libs Qt6Core Qt6Gui)
3. Run each case with a memory cap, so the runaway cases stop:
for c in finite united-nan-height united-nan-y xored-nan-height xored-nan-x;
do
(ulimit -v 1000000; timeout 10 ./regionf-nan $c; echo "$c: exit $?")
done
OBSERVED RESULT
- finite: finishes at once, 3 rects.
- united-nan-height: loops in unite() -> sliceBand() ->
QList<RectF>::emplaceBack() until
the address-space cap; it allocates about 1.3 GB/s (0.8 s with a 1 GB cap,
5.6 s with
8 GB), then crashes when the allocation fails.
- united-nan-y: SIGSEGV after about 0.1 s in RegionF::mergeBands() called from
unite(),
whatever the cap.
- xored-nan-height: loops and allocates like united-nan-height.
- xored-nan-x: never returns; 100 % of one core in RegionF::xorBands() (called
from
exclusiveOr()), with constant memory (killed by timeout after 10 s).
The order of the operands matters: other.united(RegionF(0, 0, 100, nan))
finishes. With
one-rectangle regions, subtracted() and intersected() return through their
early paths and
finish; I did not build a multi-rectangle case for their band code, which has
the same
"bottom() == scanline" pattern.
In the session the same thing happened inside kwin_wayland. The kernel logged
page
allocation failures with kwin_wayland's user-space RIP in libkwin.so.6.7.6 at
file offset
0x264c4f, a store inside the inlined QList<RectF>::emplaceBack() helper that
RegionF's band
functions call. The faulting code was
vmovdqu (%rdi),%ymm0; mov %r12,%rdx; add $1,%r12; shl $5,%rdx; vmovdqu
%ymm0,(%r8,%rdx,1)
so R12 is the list's size: 0x552bb700 (1.43 billion 32-byte RectF, 45.8 GB) at
the first
failure, and 0x6a8b4800 (1.79 billion, 57.2 GB) 29 seconds later while the
system swapped.
System memory went from 18 GB used to all 64 GB in about 35 seconds, then 24 GB
of swap
filled in 45 seconds:
Out of memory: Killed process 5369 (kwin_wayland) total-vm:137416728kB,
anon-rss:53018400kB, file-rss:50764kB, shmem-rss:103756kB, UID:1000
pgtables:136948kB oom_score_adj:200
What happened just before, in case it helps find the NaN's source: Spectacle
had been
started with its shortcut about three minutes earlier and was still running,
and a few
seconds before the hang plasmashell's task manager tooltip asked for a
screencast of a
window that no longer existed ("error creating screencast ... Could not find
window id
{...}", logged localized, twice). The session had run for 3 h 45 min with
kwin_wayland at
normal memory use (213-740 MB peaks in previous sessions).
EXPECTED RESULT
RegionF operations return for any input. A rectangle with a non-finite
coordinate should be
rejected or treated as empty (perhaps with a qCWarning, so the code that
produces it can be
found), instead of hanging the compositor and taking all memory on the machine.
SOFTWARE/OS VERSIONS
Linux: Gentoo Linux, kernel 7.3.4
KDE Plasma Version: 6.7.6 (Wayland session)
KDE Frameworks Version: 6.31.0
Qt Version: 6.11.3
Graphics: NVIDIA GeForce RTX 5060 Ti, driver 595.112.07 (open kernel module);
two 3840x2160 outputs at 150 % scale
ADDITIONAL INFORMATION
src/core/region.cpp is unchanged on master and Plasma/6.8 since March 2026, so
the loops are
still there.
Analyzed, re-created the issue and generated this report using Claude Code 5.5.
Let me know if any further information is needed.
--
You are receiving this mail because:
You are watching all bug changes.