Repository navigation
Decode IPv4-mapped IPv6 addresses in PG::TextDecoder::Inet - #772
Merged
Merged
Conversation
PostgreSQL prints IPv4-mapped and IPv4-compatible IPv6 addresses in dotted form, like ::ffff:1.2.3.4. The decoder chose AF_INET whenever the text contained a dot, so inet_pton() rejected these values and decoding raised TypeError. Choose AF_INET6 when the text contains a colon instead.
Collaborator
|
Thank you, this looks good! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PostgreSQL prints IPv4-mapped (and the old IPv4-compatible) IPv6 addresses in dotted form, e.g.
::ffff:192.168.1.1/128.PG::TextDecoder::Inetcan't decode those, so withPG::BasicTypeMapForResultsthe whole result fails:The decoder picks the address family with
strchr(val, '.') ? AF_INET : AF_INET6, so these values go toinet_pton(AF_INET, ...), which rejects them. The same happens forcidr(e.g.::ffff:10.0.0.0/104). These addresses show up in columns that store client addresses, since a dual-stack socket reports IPv4 peers as::ffff:a.b.c.d. Encoding the sameIPAddralready works; only decoding fails.This checks for
':'instead: IPv6 text always contains one and IPv4 text never does. I added a few mapped addresses to the existing inet and cidr cases inbasic_type_map_for_results_spec.rb; they fail without the change and pass with it. The Windows branch of the decoder usesIPAddr.newand isn't touched, and host-bit masking (#353) is unchanged.Reproduced with 1.5.4, 1.6.3 and master on macOS. The line dates back to when the decoder was added in 1.1.0.
I found this while reviewing the decoders with an AI assistant; I verified the repro and the fix myself.