Skip to content

Commit

Permalink
Fix integer overflow calculating length of very large playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Sep 14, 2024
1 parent a3a0728 commit 3ce06ad
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/playlist/Length.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

#include <fmt/format.h>

static SignedSongTime get_duration(const DetachedSong &song) {
static uint_least64_t get_duration(const DetachedSong &song) {
const auto duration = song.GetDuration();
return duration.IsNegative() ? (SignedSongTime)0 : song.GetDuration();
return duration.IsNegative() ? (uint_least64_t)0 : duration.RoundS();
}

static void
Expand All @@ -36,15 +36,15 @@ playlist_provider_length(Response &r,

std::unique_ptr<DetachedSong> song;
unsigned i = 0;
SignedSongTime playtime = (SignedSongTime)0;
uint_least64_t playtime = 0;
while ((song = e.NextSong()) != nullptr) {
if (playlist_check_translate_song(*song, base_uri,
loader))
playtime += get_duration(*song);
i++;
}
r.Fmt(FMT_STRING("songs: {}\n"), i);
r.Fmt(FMT_STRING("playtime: {}\n"), playtime.RoundS());
r.Fmt(FMT_STRING("playtime: {}\n"), playtime);
}

void
Expand Down

0 comments on commit 3ce06ad

Please sign in to comment.