wayland: add error handling for QFile::open failure in org_kde_plasma_window_get_icon

when creating a QDataStream object, if the file has not been successfully opened
before (file.open() fails), the created QDataStream object 'ds' may not function
properly. If you continue to perform the operation 'ds << icon;' in this case,
it may cause kwin to crash. Therefore, it is essential to ensure that the file
has been successfully opened before creating the QDataStream object.

Signed-off-by: likai <likai@kylinos.cn>
This commit is contained in:
Kai Li 2024-07-05 09:30:24 +08:00
parent 23e1f10c22
commit e4a272e166

View file

@ -506,7 +506,11 @@ void PlasmaWindowInterfacePrivate::org_kde_plasma_window_get_icon(Resource *reso
{
QThreadPool::globalInstance()->start([fd, icon = m_icon]() {
QFile file;
file.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle);
if (!file.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle)) {
close(fd);
qCWarning(KWIN_CORE) << Q_FUNC_INFO << "failed to open file:" << file.errorString();
return;
}
QDataStream ds(&file);
ds << icon;
file.close();