shithub: sox

Download patch

ref: 283920fc379c560a2fcd292f26e65ebed182e2a0
parent: f720b34328fbc42b7ad23a94d29fa1b50a6aa359
author: Helmut Grohne <helmut@subdivi.de>
date: Wed Aug 16 22:02:12 EDT 2023

sphere: avoid integer underflow

--- a/src/sphere.c
+++ b/src/sphere.c
@@ -63,7 +63,8 @@
     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 @@
       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)