]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
play: Fix some integer overflows().
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 19 Apr 2024 18:35:02 +0000 (20:35 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 18 May 2024 20:28:32 +0000 (22:28 +0200)
If one factor of a product is a chunk number, we need to be careful
with respect to integer overflows. This patch adds casts which force
64 bit arithmetics to avoid that.

The overflows were observed while navigating a ~4 hour mp3 file.

play.c

diff --git a/play.c b/play.c
index ffdc8555ce6686833b846f9610a3d81f6adf03cb..f28a324c30a2554a10de558b1fb0f3d2e5990e67 100644 (file)
--- a/play.c
+++ b/play.c
@@ -202,7 +202,7 @@ static long unsigned get_play_time(void)
        if (pt->num_chunks == 0 || pt->seconds == 0)
                return 0;
        /* where the stream started (in seconds) */
-       result = pt->start_chunk * pt->seconds / pt->num_chunks;
+       result = (uint64_t)pt->start_chunk * pt->seconds / pt->num_chunks;
        if (pt->wn.btrn) { /* Add the uptime of the writer node */
                struct timeval diff = {.tv_sec = 0}, wstime;
                btr_get_node_start(pt->wn.btrn, &wstime);
@@ -925,7 +925,7 @@ static int com_jmp(struct lls_parse_result *lpr)
                return com_next(NULL);
        if (pt->playing && !pt->fn.btrn)
                return 0;
-       pt->start_chunk = percent * pt->num_chunks / 100;
+       pt->start_chunk = (uint64_t)percent * pt->num_chunks / 100;
        if (!pt->playing)
                return 0;
        pt->rq = CRT_REPOS;
@@ -955,7 +955,7 @@ static int com_ff(struct lls_parse_result *lpr)
        seconds += get_play_time();
        seconds = PARA_MIN(seconds, (typeof(seconds))pt->seconds - 4);
        seconds = PARA_MAX(seconds, 0);
-       pt->start_chunk = pt->num_chunks * seconds / pt->seconds;
+       pt->start_chunk = (uint64_t)pt->num_chunks * seconds / pt->seconds;
        pt->start_chunk = PARA_MIN(pt->start_chunk, pt->num_chunks - 1);
        pt->start_chunk = PARA_MAX(pt->start_chunk, 0UL);
        if (!pt->playing)