Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer overflow calculating length of very large playlists #2116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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