From f801dc0886f9c3bcda193bc37d475f4c0da1099a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 2 Nov 2022 11:43:30 +0100 Subject: [PATCH] pulse-server: keep read index in sync Keep the ringbuffer and read_index variable in sync or else we might ask for more data than maxlength and cause an overflow. Fixes #2799 --- src/modules/module-protocol-pulse/pulse-server.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 7cbe275bc..b18273e98 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -1428,15 +1428,16 @@ static void stream_process(void *data) } if ((stream->attr.prebuf == 0 || do_flush) && !stream->corked) { if (avail > 0) { + avail = SPA_MIN((uint32_t)avail, size); spa_ringbuffer_read_data(&stream->ring, stream->buffer, MAXLENGTH, index % MAXLENGTH, - p, SPA_MIN((uint32_t)avail, size)); + p, avail); index += avail; + pd.read_inc = avail; + spa_ringbuffer_read_update(&stream->ring, index); } pd.playing_for = size; - pd.read_inc = size; - spa_ringbuffer_read_update(&stream->ring, index); } pw_log_debug("%p: [%s] underrun read:%u avail:%d max:%u", stream, client->name, index, avail, minreq);