From 4ebb21e8c3f259c552df2f1d693988fb564ba74a Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 9 Apr 2024 00:49:27 +0300 Subject: [PATCH] plugins/screencast: Refuse creating a dmabuf buffer if n_datas is wrong n_datas must match the plane count in the graphics buffer. But apparently pw buffers with wrong n_datas can still slip through somehow. It makes the screen cast stream crash when filling in buffer data. The crash is hard to reproduce, but on the other hand, according to sentry, a substantial number of users is affected by this issue. Taking the defensive approach is not great, there will likely be other issues with screencasting, but it seems like the only feasible option so far. Broken streams is better than kwin crashing. It also wouldn't hurt to add some warning messages, that will be done in a follow up MR. --- src/plugins/screencast/screencastbuffer.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugins/screencast/screencastbuffer.cpp b/src/plugins/screencast/screencastbuffer.cpp index 329f75e460..a2b1bbe912 100644 --- a/src/plugins/screencast/screencastbuffer.cpp +++ b/src/plugins/screencast/screencastbuffer.cpp @@ -49,6 +49,11 @@ DmaBufScreenCastBuffer *DmaBufScreenCastBuffer::create(pw_buffer *pwBuffer, cons return nullptr; } + if (pwBuffer->buffer->n_datas != uint32_t(attrs->planeCount)) { + buffer->drop(); + return nullptr; + } + backend->makeCurrent(); auto texture = backend->importDmaBufAsTexture(*attrs); @@ -64,8 +69,6 @@ DmaBufScreenCastBuffer *DmaBufScreenCastBuffer::create(pw_buffer *pwBuffer, cons } struct spa_data *spaData = pwBuffer->buffer->datas; - - Q_ASSERT(pwBuffer->buffer->n_datas >= uint(attrs->planeCount)); for (int i = 0; i < attrs->planeCount; ++i) { spaData[i].type = SPA_DATA_DmaBuf; spaData[i].flags = SPA_DATA_FLAG_READWRITE;