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

store allows constructing Ratio with zero denominator #127

Open
k0001 opened this issue Apr 15, 2018 · 0 comments
Open

store allows constructing Ratio with zero denominator #127

k0001 opened this issue Apr 15, 2018 · 0 comments

Comments

@k0001
Copy link
Contributor

k0001 commented Apr 15, 2018

Rational numbers can't contain a zero denominator. Smart constructors such as Data.Ratio.(%) prevent this, but store allows it.

Data.Store.decodeEx "\NUL\001\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\000\NUL\NUL\NUL\NUL\NUL\NUL\NUL" :: Rational 
1 % 0

> Data.Store.decodeEx "\NUL\000\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\000\NUL\NUL\NUL\NUL\NUL\NUL\NUL" :: Rational 
0 % 0

> Data.Store.decodeEx "\001\NUL\NUL\NUL\000\NUL\NUL\NUL" :: Ratio Int32
1 % 0

> Data.Store.decodeEx "\000\NUL\NUL\NUL\000\NUL\NUL\NUL" :: Ratio Int32
0 % 0

For comparison, other serialization/deserialization libraries take care of preventing a zero denominator (see k0001/safe-money#21)

Other than showing it, there's no much you can do with a Ratio with a zero denominator, since most operations on them fail. For example:

> 1 + (Data.Store.decodeEx "\000\NUL\NUL\NUL\000\NUL\NUL\NUL" :: Ratio Int32)
*** Exception: Ratio has zero denominator

store should always fail to parse Ratios that have a zero denominator.

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

No branches or pull requests

1 participant