QVnc: clip requested screen region to available screen image

Avoid potential oob memory access.

Pick-to: 6.1 6.0 5.15 5.12
Fixes: QTBUG-91770
Change-Id: I34fff1cf8dec5275572a027288b0e8310359d9f8
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Eirik Aavitsland 2021-04-29 13:46:15 +02:00
parent bb8fc324d1
commit c494c1e875

View File

@ -477,6 +477,9 @@ void QRfbRawEncoder::write()
// server->screen()->geometry().height()); // server->screen()->geometry().height());
// } // }
const QImage screenImage = client->server()->screenImage();
rgn &= screenImage.rect();
const auto rectsInRegion = rgn.rectCount(); const auto rectsInRegion = rgn.rectCount();
{ {
@ -492,8 +495,6 @@ void QRfbRawEncoder::write()
if (rectsInRegion <= 0) if (rectsInRegion <= 0)
return; return;
const QImage screenImage = client->server()->screenImage();
for (const QRect &tileRect: rgn) { for (const QRect &tileRect: rgn) {
const QRfbRect rect(tileRect.x(), tileRect.y(), const QRfbRect rect(tileRect.x(), tileRect.y(),
tileRect.width(), tileRect.height()); tileRect.width(), tileRect.height());