{"action":"created","issue":{"url":"https://api.github.com/repos/musescore/MuseScore/issues/1953","labels_url":"https://api.github.com/repos/musescore/MuseScore/issues/1953/labels{/name}","comments_url":"https://api.github.com/repos/musescore/MuseScore/issues/1953/comments","events_url":"https://api.github.com/repos/musescore/MuseScore/issues/1953/events","html_url":"https://github.com/musescore/MuseScore/pull/1953","id":69153854,"number":1953,"title":"fix #56651: Crash when importing/previewing MIDI files with high divisio...","user":{"login":"heuchi","id":2162327,"avatar_url":"https://avatars.githubusercontent.com/u/2162327?v=3","gravatar_id":"","url":"https://api.github.com/users/heuchi","html_url":"https://github.com/heuchi","followers_url":"https://api.github.com/users/heuchi/followers","following_url":"https://api.github.com/users/heuchi/following{/other_user}","gists_url":"https://api.github.com/users/heuchi/gists{/gist_id}","starred_url":"https://api.github.com/users/heuchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heuchi/subscriptions","organizations_url":"https://api.github.com/users/heuchi/orgs","repos_url":"https://api.github.com/users/heuchi/repos","events_url":"https://api.github.com/users/heuchi/events{/privacy}","received_events_url":"https://api.github.com/users/heuchi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-17T14:51:03Z","updated_at":"2015-04-18T20:18:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/musescore/MuseScore/pulls/1953","html_url":"https://github.com/musescore/MuseScore/pull/1953","diff_url":"https://github.com/musescore/MuseScore/pull/1953.diff","patch_url":"https://github.com/musescore/MuseScore/pull/1953.patch"},"body":"To prevent an overflow of (tick * MScore::division) I divided numerator and denominator of the right side of the equation with the gcd of tick and oldDivision:\r\n<pre>\r\n                  tick * MScore::division + oldDivision / 2\r\nMuseScoreTick =  -------------------------------------------\r\n                                 oldDivision\r\n</pre>\r\nright side multiplied with (1/gcd) : (1/gcd) with gcd = greatest common divisor of tick and oldDivision.\r\nBecause of (1/gcd) : (1/gcd) = 1 and gcd != 0, this doesn't change the value of the right side.\r\n<pre>\r\n                 tick/gcd * MScore::division + (oldDivision/gcd) / 2\r\nMuseScoreTick =  ----------------------------------------------------\r\n                                  oldDivision / gcd\r\n</pre>\r\nThat means we can simply replace\r\ntick with (tick / gcd) and oldDivision with (oldDivision / gcd)\r\nbecause we know, both can be divided by gcd.\r\nAs a result, we have a high chance of avoiding the multiplication overflow."},"comment":{"url":"https://api.github.com/repos/musescore/MuseScore/issues/comments/94198071","html_url":"https://github.com/musescore/MuseScore/pull/1953#issuecomment-94198071","issue_url":"https://api.github.com/repos/musescore/MuseScore/issues/1953","id":94198071,"user":{"login":"trig-ger","id":3074686,"avatar_url":"https://avatars.githubusercontent.com/u/3074686?v=3","gravatar_id":"","url":"https://api.github.com/users/trig-ger","html_url":"https://github.com/trig-ger","followers_url":"https://api.github.com/users/trig-ger/followers","following_url":"https://api.github.com/users/trig-ger/following{/other_user}","gists_url":"https://api.github.com/users/trig-ger/gists{/gist_id}","starred_url":"https://api.github.com/users/trig-ger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trig-ger/subscriptions","organizations_url":"https://api.github.com/users/trig-ger/orgs","repos_url":"https://api.github.com/users/trig-ger/repos","events_url":"https://api.github.com/users/trig-ger/events{/privacy}","received_events_url":"https://api.github.com/users/trig-ger/received_events","type":"User","site_admin":false},"created_at":"2015-04-18T20:18:26Z","updated_at":"2015-04-18T20:18:26Z","body":"@heuchi: thanks for reporting this.\r\nHere is an 'integral-remainder' version to prevent overflow:\r\nhttps://github.com/musescore/MuseScore/pull/1958\r\n\r\nIt's the same as the solution for ReducedFraction::ticks() function\r\nnot used here accidentally until now."}}