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 80431be
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/playlist/Length.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 80431be

Please sign in to comment.