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 27, 2024
1 parent a3a0728 commit 88eb713
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/playlist/Length.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <fmt/format.h>

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

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

std::unique_ptr<DetachedSong> 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))
playtime += get_duration(*song);
i++;
}
r.Fmt(FMT_STRING("songs: {}\n"), i);
r.Fmt(FMT_STRING("playtime: {}\n"), playtime.RoundS());
const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(playtime);
r.Fmt(FMT_STRING("playtime: {}\n"), seconds.count());
}

void
Expand Down

0 comments on commit 88eb713

Please sign in to comment.