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

Conversation

jcorporation
Copy link
Member

No description provided.

@MaxKellermann
Copy link
Member

This loses type safety by downgrading from std::chrono to raw integers, but what do these raw integers mean? You make the core more obscure and less safe.

@jcorporation jcorporation force-pushed the playlistlength_fix branch 2 times, most recently from 88eb713 to 80431be Compare September 27, 2024 17:42
@jcorporation
Copy link
Member Author

Ok, migrated it to std::chrono::duration api.

Comment on lines 47 to 48
const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(playtime);
r.Fmt(FMT_STRING("playtime: {}\n"), seconds.count());
Copy link
Member

Choose a reason for hiding this comment

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

This removes the rounding which was very explicit previously

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with std::chrono::round

@@ -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

@MaxKellermann MaxKellermann merged commit 030bac4 into MusicPlayerDaemon:master Oct 26, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants