Skip to content

Conversation

@salvatore-campagna
Copy link
Contributor

@salvatore-campagna salvatore-campagna commented Dec 12, 2025

Follow-up to #139420.

While investigating IPv6 address handling, I found that indexing documents with certain valid IPv6 addresses fails with:

DocumentParsingException: [1:10] failed to parse field [field] of type [ip] in document with id '1'.
Preview of field's value: '::1:2:3:4:5:6:7'

Caused by:
IllegalArgumentException: '::1:2:3:4:5:6:7' is not an IP string literal.

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 in textToNumericFormatV6(). The bug causes the parser to count an extra empty hextet at the start as a result of starting parsing from index 0 rather than from offset. 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 hextetIndex to 8, triggering the hextetIndex >= IPV6_PART_COUNT check and returning null. With fewer hextets, the :: compression absorbs the extra count, hiding the bug.

The fix includes:

  • updating currentHextetStart which was initialized to 0 but should be offset
  • updating the check i != 1 (for allowing :: at the start) which should be i != offset + 1
  • updated the assertion in InetAddressesTests.testWithOffsets() to compare InetAddress objects instead of string representations, since ::1:2:3:4:5:6:7 normalizes to 0:1:2:3:4:5:6:7 when converted back to string

Added test cases to InetAddressesTests.testWithOffsets() and a new test IpFieldMapperTests.testIPv6WithMaxHextets() to cover this scenario.

IPv6 addresses starting with "::" followed by 7 hextets (e.g.,
"::1:2:3:4:5:6:7") were incorrectly rejected when parsed from a
byte array with a non-zero offset. This caused document indexing
failures for valid IP addresses.

Two fixes in textToNumericFormatV6():
- Initialize currentHextetStart to offset instead of 0
- Change the check "i != 1" to "i != offset + 1" for detecting
  the second colon of a leading "::"

The bug caused the parser to count an extra spurious hextet at the
start, pushing hextetIndex to 8, which then failed the validation
check "hextetIndex >= IPV6_PART_COUNT" and returned null.

Added test cases to InetAddressesTests.testWithOffsets() and a new
test IpFieldMapperTests.testIPv6WithMaxHextets() to cover this
scenario.
@salvatore-campagna salvatore-campagna self-assigned this Dec 12, 2025
@salvatore-campagna salvatore-campagna requested a review from a team as a code owner December 12, 2025 16:46
@salvatore-campagna salvatore-campagna added >bug auto-backport Automatically create backport pull requests when merged Team:StorageEngine :StorageEngine/Mapping The storage related side of mappings v9.2.4 labels Dec 12, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@elasticsearchmachine
Copy link
Collaborator

Hi @salvatore-campagna, I've created a changelog YAML for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :StorageEngine/Mapping The storage related side of mappings Team:StorageEngine v9.2.4 v9.3.0

2 participants