From 27211856eba0c3d288571b733bf391c63a15e7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 8 Sep 2022 09:14:19 +0200 Subject: [PATCH] pulse-server: Handle overlong writes from clients When a client writes more then requested, let the requested field go negative so that it is taken into account the next time we ask for more data. Also the requested field follows the difference in the write pointer caused by seeks. See #2626 Fixes #2674 --- src/modules/module-protocol-pulse/server.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/module-protocol-pulse/server.c b/src/modules/module-protocol-pulse/server.c index b363a66bc..7bfbd034d 100644 --- a/src/modules/module-protocol-pulse/server.c +++ b/src/modules/module-protocol-pulse/server.c @@ -166,6 +166,7 @@ static int handle_memblock(struct client *client, struct message *msg) index += diff; filled += diff; stream->write_index += diff; + stream->requested -= diff; if (filled < 0) { /* underrun, reported on reader side */ @@ -182,9 +183,10 @@ static int handle_memblock(struct client *client, struct message *msg) msg->data, SPA_MIN(msg->length, MAXLENGTH)); index += msg->length; - stream->write_index += msg->length; spa_ringbuffer_write_update(&stream->ring, index); - stream->requested -= SPA_MIN(msg->length, stream->requested); + + stream->write_index += msg->length; + stream->requested -= msg->length; stream_send_request(stream);