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.
This commit is contained in:
Vlad Zahorodnii 2024-04-09 00:49:27 +03:00
parent 886f0e852b
commit 4ebb21e8c3

View file

@ -49,6 +49,11 @@ DmaBufScreenCastBuffer *DmaBufScreenCastBuffer::create(pw_buffer *pwBuffer, cons
return nullptr; return nullptr;
} }
if (pwBuffer->buffer->n_datas != uint32_t(attrs->planeCount)) {
buffer->drop();
return nullptr;
}
backend->makeCurrent(); backend->makeCurrent();
auto texture = backend->importDmaBufAsTexture(*attrs); auto texture = backend->importDmaBufAsTexture(*attrs);
@ -64,8 +69,6 @@ DmaBufScreenCastBuffer *DmaBufScreenCastBuffer::create(pw_buffer *pwBuffer, cons
} }
struct spa_data *spaData = pwBuffer->buffer->datas; struct spa_data *spaData = pwBuffer->buffer->datas;
Q_ASSERT(pwBuffer->buffer->n_datas >= uint(attrs->planeCount));
for (int i = 0; i < attrs->planeCount; ++i) { for (int i = 0; i < attrs->planeCount; ++i) {
spaData[i].type = SPA_DATA_DmaBuf; spaData[i].type = SPA_DATA_DmaBuf;
spaData[i].flags = SPA_DATA_FLAG_READWRITE; spaData[i].flags = SPA_DATA_FLAG_READWRITE;