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
IPv4 octet parsing subject to Word overflow #74
Comments
If anyone wants to fix this, I would accept a PR for it. EDIT: Also, thanks for reporting. |
You are welcome! I just submitted a PR with a fix. |
I went for a hike this afternoon and realized that my comment about If you have any ideas for further improvement or other suggestions, please feel free to let me know, and I would be happy to look into them. |
Add IPv4 octet overflow test and fix IPv4 octet overflow bug
Resolved in #75 |
All processed characters are guaranteed to be digits (0~9) through use of `Char.isDigit`, so the range check in helper function `go` is not necessary.
I realized that the diff --git a/src/Net/IPv4.hs b/src/Net/IPv4.hs
index 40459d7..a020582 100644
--- a/src/Net/IPv4.hs
+++ b/src/Net/IPv4.hs
@@ -771,9 +771,8 @@ readOctet t = do
where
go :: Char -> (Int -> Maybe Int) -> Int -> Maybe Int
go !d !f !n =
- let d' = Char.ord d - 48
- n' = n * 10 + d'
- in if d' >= 0 && d' <=9 && n' <= 255 then f n' else Nothing
+ let n' = n * 10 + Char.ord d - 48
+ in if n' <= 255 then f n' else Nothing
stripDecimal :: Text -> Either String Text
stripDecimal t = case Text.uncons t of Sorry for not noticing that before! If you would like to commit this optimization, I can create a PR. |
Yeah, go ahead and PR. That would be great. |
All processed characters are guaranteed to be digits (0~9) through use of `Char.isDigit`, so the range check in helper function `go` is not necessary.
The
decodeIPv4TextReader
function usesTextRead.decimal
to parseWord
values. SinceWord
is a bounded type, it is subject to overflow, which causes some invalid strings to parse successfully.Example:
I do not think that this issue is significant, but I figure that I should at least report it.
The text was updated successfully, but these errors were encountered: