From 25f686e0da423326a74fe16c603b6b6b75857fa4 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 16 Mar 2025 20:07:19 +0100 Subject: [PATCH] sphere: avoid integer underflow Source: https://salsa.debian.org/lts-team/packages/sox/-/blob/debian/14.4.2+git20190427-1+deb10u3/debian/patches/CVE-2021-40426.patch CVE: CVE-2021-40426 Upstream-Status: Inactive-Upstream [lastrelease: 2015] Signed-off-by: Peter Marko --- src/sphere.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sphere.c b/src/sphere.c index a3fd1c64..9544d160 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -63,7 +63,8 @@ static int start_read(sox_format_t * ft) return (SOX_EOF); } - header_size -= (strlen(buf) + 1); + bytes_read = strlen(buf); + header_size -= bytes_read >= header_size ? header_size : bytes_read + 1; while (strncmp(buf, "end_head", (size_t)8) != 0) { if (strncmp(buf, "sample_n_bytes", (size_t)14) == 0) @@ -105,7 +106,8 @@ static int start_read(sox_format_t * ft) return (SOX_EOF); } - header_size -= (strlen(buf) + 1); + bytes_read = strlen(buf); + header_size -= bytes_read >= header_size ? header_size : bytes_read + 1; } if (!bytes_per_sample)