-
Notifications
You must be signed in to change notification settings - Fork 37
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
ntop: Measure address size in bytes #61
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPAddr.ntop() (naturally) expects a binary string, so in terms of user-friendliness, it would make sense to check the encoding and raise an EncodingError if the given string is not binary.
Makes sense. I just though such a change would break compatibility, but actually the affected user codes have never worked correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think using bytesize here is technically correct, accepting a non-binary string is not what we want. Would you care to add encoding check?
dab4c25
to
d1e85d0
Compare
@knu I just updated the patch. Please take a look. |
d1e85d0
to
88652ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
@@ -111,7 +111,11 @@ def self.new_ntoh(addr) | |||
# Convert a network byte ordered string form of an IP address into | |||
# human readable form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add something like this here? "It expects a string encoded in Encoding::ASCII_8BIT."
88652ff
to
be01430
Compare
lib/ipaddr.rb
Outdated
@@ -110,8 +110,13 @@ def self.new_ntoh(addr) | |||
|
|||
# Convert a network byte ordered string form of an IP address into | |||
# human readable form. | |||
# It expects the string to be encoded in Encoding::US_ASCII (BINARY). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encoding::US_ASCII is different from ASCII_8BIT. US_ASCII is a 7-bit encoding where codes above 127 cannot be contained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy&pasted wrong string 😓
`IPAddr.ntop` takes the binary representation of an IP address, whose length should be 4 or 16 *bytes* (not characters/codepoints). The current implementation accepts strings in any encoding, but for some values in non-BINARY encoding, it fails proper length check and raises an `AddressFamilyError`. Since passing strings in a multibyte encoding has never worked correctly for years, this patch makes it an explicit error with an `InvalidAddressError`. Fixes: ruby#56
be01430
to
a33fd14
Compare
IPAddr.ntop
takes the binary representation of an IP address, whose length should be 4 or 16 bytes (not characters/codepoints).This patch fixes the bug that
IPAddr.ntop
doesn't handle Strings in a multibyte encoding correctly.Fixes: #56