XdgToplevelIcon: Reserve instead of resize list

resize() changes the size of the list, reserve() changes the capacity.

If we resize and then append we end up with too many items, some of
which are default-constructed (invalid) sizes.

Later we use the invalid size to get a pixmap, which will be empty.

In QWaylandShmBuffer we then try to mmap the empty pixmap, which fails
and we return early, never calling init() and setting mBuffer.

In QWaylandXdgToplevelIconV1 we then pass this null buffer
to add_buffer, which results in a protocol error

Fixes: QTBUG-132727
Pick-to: 6.9
Change-Id: I8f164c43423726367157fa9ce2e3af7a6fd3219c
Reviewed-by: David Redondo <qt@david-redondo.de>
This commit is contained in:
Nicolas Fella 2025-01-12 03:42:46 +01:00
parent 33db27aeaf
commit 74e57c5d9d

View File

@ -79,7 +79,7 @@ void QWaylandXdgToplevelIconManagerV1::setIcon(const QIcon &icon, xdg_toplevel *
QList<QSize> iconSizes = icon.availableSizes();
// if icon has no default size (an SVG)
if (iconSizes.isEmpty()) {
iconSizes.resize(mPreferredSizes.size());
iconSizes.reserve(mPreferredSizes.size());
for (int size : std::as_const(mPreferredSizes)) {
iconSizes.append(QSize(size, size));
}