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

Merged
Merged
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I get the song duration in the local variable there is no need to call the GetDuration function a second time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but it doesn't fix an integer overflow

}

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::round<std::chrono::seconds>(playtime);
r.Fmt(FMT_STRING("playtime: {}\n"), seconds.count());
}

void
Expand Down