From 15d09694e9dbb4766621061786c5ea225c54c961 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 19 Apr 2024 20:35:02 +0200 Subject: [PATCH] play: Fix some integer overflows(). 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/play.c b/play.c index ffdc8555..f28a324c 100644 --- 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) -- 2.39.5