From 49ddb12cc514ad1a77c665aacbf3e4eae168087b Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Tue, 31 Mar 2026 01:12:16 +0300 Subject: [PATCH] utils: sofprobeclient: fix parser buffer overflow on large reads The compress device may return more data than the parser's internal buffer (DATA_READ_LIMIT, 4096 bytes) can accept in one call. Feed captured data in a loop, copying only as much as parser_fetch_free_buffer() reports available per iteration. This fixes truncated probe packets that caused checksum errors and missing log lines. Closes: https://github.com/alsa-project/tinycompress/pull/35 Signed-off-by: Jyri Sarha Signed-off-by: Jaroslav Kysela --- src/utils/sofprobeclient.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/utils/sofprobeclient.c b/src/utils/sofprobeclient.c index e5b4aea..6e10b44 100644 --- a/src/utils/sofprobeclient.c +++ b/src/utils/sofprobeclient.c @@ -219,20 +219,27 @@ static void capture_and_parse(unsigned int card, unsigned int device, } if (read > 0) { + int remaining = read; + char *src = buffer; + total_read += read; - /* Feed captured data into the probe parser */ - parser_fetch_free_buffer(parser, &parse_buf, &parse_len); - if ((size_t)read > parse_len) { - fprintf(stderr, "Warning: read %d > parser buffer %zu, truncating\n", - read, parse_len); - read = parse_len; - } - memcpy(parse_buf, buffer, read); - ret = parser_parse_data(parser, read); - if (ret < 0) { - fprintf(stderr, "Parser error %d, stopping\n", ret); - goto buf_exit; + /* Feed captured data to the parser in chunks + * that fit its internal buffer. + */ + while (remaining > 0) { + int chunk; + + parser_fetch_free_buffer(parser, &parse_buf, &parse_len); + chunk = remaining < (int)parse_len ? remaining : (int)parse_len; + memcpy(parse_buf, src, chunk); + ret = parser_parse_data(parser, chunk); + if (ret < 0) { + fprintf(stderr, "Parser error %d, stopping\n", ret); + goto buf_exit; + } + src += chunk; + remaining -= chunk; } if (verbose) { -- 2.52.0