From 052719c0e446b6a3d3c24fe4f7b36339a7402048 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Sat, 14 Sep 2024 13:34:26 +0200 Subject: [PATCH] Fix integer overflow calculating length of very large playlists --- src/playlist/Length.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/playlist/Length.cxx b/src/playlist/Length.cxx index 2aeecf1446..96e03fc79e 100644 --- a/src/playlist/Length.cxx +++ b/src/playlist/Length.cxx @@ -21,7 +21,7 @@ static SignedSongTime get_duration(const DetachedSong &song) { const auto duration = song.GetDuration(); - return duration.IsNegative() ? (SignedSongTime)0 : song.GetDuration(); + return duration.IsNegative() ? (SignedSongTime)0 : duration; } static void @@ -36,7 +36,7 @@ playlist_provider_length(Response &r, std::unique_ptr song; unsigned i = 0; - SignedSongTime playtime = (SignedSongTime)0; + std::chrono::milliseconds playtime = (std::chrono::milliseconds)0; while ((song = e.NextSong()) != nullptr) { if (playlist_check_translate_song(*song, base_uri, loader)) @@ -44,7 +44,8 @@ playlist_provider_length(Response &r, i++; } r.Fmt(FMT_STRING("songs: {}\n"), i); - r.Fmt(FMT_STRING("playtime: {}\n"), playtime.RoundS()); + const auto seconds = std::chrono::round(playtime); + r.Fmt(FMT_STRING("playtime: {}\n"), seconds.count()); } void