Bug 425790 - KRunner currency converter can't handle large values (32-bit signed int overflow)
Summary: KRunner currency converter can't handle large values (32-bit signed int overf...
Status: CONFIRMED
Alias: None
Product: frameworks-kunitconversion
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: John Layt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-25 18:43 UTC by David Korth
Modified: 2021-03-10 07:23 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
KRunner showing incorrect currency conversions due to 32-bit signed int overflow. (21.08 KB, image/png)
2020-08-25 18:43 UTC, David Korth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Korth 2020-08-25 18:43:24 UTC
Created attachment 131177 [details]
KRunner showing incorrect currency conversions due to 32-bit signed int overflow.

Attempting to convert a large currency value results in a signed integer overflow.


STEPS TO REPRODUCE
1. Enter a large currency value, e.g. "700,000,000 EUR".

OBSERVED RESULT
Converted currency values are all "-21,474,836.48".

EXPECTED RESULT
Currency should be converted correctly.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Gentoo Linux
(available in About System)
KDE Plasma Version: 5.19.2
KDE Frameworks Version: 5.73.0
Qt Version: 5.15.0
Comment 1 Alexander Lohnau 2020-08-26 05:17:05 UTC
When typing "7000000 EUR" I get invalid results for YEN, but the others are fine. So that parsing of the input seems to be fine and it is an issue with the framework.
Comment 2 Chris Holland 2021-03-07 02:27:20 UTC
The bug is somewhere in KUnitConversion::Value::round(2).
Screenshot: https://i.imgur.com/feCDHK2.png

There's an int cast:
https://invent.kde.org/frameworks/kunitconversion/-/blob/master/src/value.cpp#L184
Comment 3 Alexander Lohnau 2021-03-10 07:23:39 UTC
Git commit 7f672f1d47649ad17bfae61b97dd7f35e1e64727 by Alexander Lohnau.
Committed on 10/03/2021 at 07:23.
Pushed by alex into branch 'master'.

converterrunner: Do not round values unnecassarily

We pass in the precision when we format the string
and the rounding causes internal issues when the value is casted to an
int.

Test Plan:
Large queries like `100000000000000000000000000000000000000000$` no
longer produce negative results.

This fix can also be backported for Plasma 5.21.

M  +0    -1    runners/converter/converterrunner.cpp

https://invent.kde.org/plasma/kdeplasma-addons/commit/7f672f1d47649ad17bfae61b97dd7f35e1e64727