fix: IPv6 address parsing with non-zero offset in InetAddresses #139460
+40
−7
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.
Follow-up to #139420.
While investigating IPv6 address handling, I found that indexing documents with certain valid IPv6 addresses fails with:
The issue affects IPv6 addresses starting with
::followed by exactly 7 hextets (e.g.,::1:2:3:4:5:6:7). These are valid addresses but get rejected due to incorrect offset handling intextToNumericFormatV6(). The bug causes the parser to count an extra empty hextet at the start as a result of starting parsing from index0rather than fromoffset. IPv6 allows exactly 8 hextets, and::compression represents one or more zero hextets.The bug only manifests with exactly 7 hextets because the spurious empty hextet pushes
hextetIndexto 8, triggering thehextetIndex >= IPV6_PART_COUNTcheck and returningnull. With fewer hextets, the::compression absorbs the extra count, hiding the bug.The fix includes:
currentHextetStartwhich was initialized to0but should beoffseti != 1(for allowing::at the start) which should bei != offset + 1InetAddressesTests.testWithOffsets()to compareInetAddressobjects instead of string representations, since::1:2:3:4:5:6:7normalizes to0:1:2:3:4:5:6:7when converted back to stringAdded test cases to
InetAddressesTests.testWithOffsets()and a new testIpFieldMapperTests.testIPv6WithMaxHextets()to cover this scenario.