You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function from_str in the DECIMAL crate is used to convert a string to a decimal type. To handle the fractional part of the number, the function has the following logic:
Code snippet from the from_str function. It handles the fractional part of a string number.
As it can be noted, the assert! is a tautology since exp will always be greater or equal than DECIMAL_PLACES given that fractional_part.len() is a positive number. Given the this, then it is possible for a negative exp to pass the assert! which later will be casted to a u32 number.
Impact
At present, there is no immediate consequence to this situation. The limitation stems from the fact that the largest string permissible as input can only consist of 36 digits for its fractional part. Should this limit be exceeded, invoking fractional_part.parse() would result in a panic. Conversely, the smallest accepted value for exp is -18, which, upon being casted to u32, transforms into a substantial number making the next line with pow to panic due to an overflow.
Recommendation
The assert should be changed to assert!(exp >= 0).
The text was updated successfully, but these errors were encountered:
The function
from_str
in theDECIMAL
crate is used to convert a string to a decimal type. To handle the fractional part of the number, the function has the following logic:As it can be noted, the
assert!
is a tautology sinceexp
will always be greater or equal thanDECIMAL_PLACES
given thatfractional_part.len()
is a positive number. Given the this, then it is possible for a negativeexp
to pass theassert!
which later will be casted to au32
number.Impact
At present, there is no immediate consequence to this situation. The limitation stems from the fact that the largest string permissible as input can only consist of 36 digits for its fractional part. Should this limit be exceeded, invoking fractional_part.parse() would result in a panic. Conversely, the smallest accepted value for
exp
is-18
, which, upon being casted tou32
, transforms into a substantial number making the next line withpow
to panic due to an overflow.Recommendation
The assert should be changed to
assert!(exp >= 0)
.The text was updated successfully, but these errors were encountered: