From c34477a42acf28379a912aa3511efe44c7e6f1f1 Mon Sep 17 00:00:00 2001 From: Ye ShanShan Date: Wed, 10 Apr 2024 21:44:58 +0800 Subject: [PATCH] fix: BlurArea unpack error in qt5 incorrect count is assigned in *(reinterpret_cast*>(&area), it causes invalid BlurArea, and causes memory leakage. It causes in the commit https://github.com/linuxdeepin/dtkgui/pull/232 --- xcb/dnotitlebarwindowhelper.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/xcb/dnotitlebarwindowhelper.cpp b/xcb/dnotitlebarwindowhelper.cpp index 727aeb42..65a4fd57 100644 --- a/xcb/dnotitlebarwindowhelper.cpp +++ b/xcb/dnotitlebarwindowhelper.cpp @@ -411,7 +411,21 @@ void DNoTitlebarWindowHelper::updateWindowBlurAreasFromProperty() { const QVariant &v = m_window->property(windowBlurAreas); const QVector &tmpV = qvariant_cast>(v); - const QVector &a = *(reinterpret_cast*>(&tmpV)); + const int OffSet = 6; // Utility::BlurArea's member variables + if (tmpV.size() % OffSet != 0) + qt_assert("windowBlurAreas's size must be round out BlurAreas's member variables.", __FILE__, __LINE__); + + QVector a; + for (int i = 0; i < tmpV.size(); i += OffSet) { + Utility::BlurArea area; + area.x = tmpV[i + 0]; + area.y = tmpV[i + 1]; + area.width = tmpV[i + 2]; + area.height = tmpV[i + 3]; + area.xRadius = tmpV[i + 4]; + area.yRaduis = tmpV[i + 5]; + a << area; + } if (a.isEmpty() && m_blurAreaList.isEmpty()) return;