Conversation
knu
left a comment
There was a problem hiding this comment.
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. |
knu
left a comment
There was a problem hiding this comment.
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
| @@ -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.
Could you add something like this here? "It expects a string encoded in Encoding::ASCII_8BIT."
88652ff to
be01430
Compare
lib/ipaddr.rb
Outdated
|
|
||
| # 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.
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.
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.ntoptakes 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.ntopdoesn't handle Strings in a multibyte encoding correctly.Fixes: #56