-
Notifications
You must be signed in to change notification settings - Fork 74
Description
I'm ipaddress version 5.3.4 on Java 8.
My use-case is that I have multiple ranges of IPs, both IPv4 and IPv6 (possibly with various overlaps), and I want to compact them all, and later do a binary search on the sorted array given by IPAddressSeqRange.join() to quickly check if a given IP (v4 or v6) is in any of those ranges.
join() seems to work fine with a mix of IPv4 and IPv6, but I encountered one annoying edge case where the ranges span all possible v4 and v6 addresses.
I have not encountered problems when trying to join full IPv4 range with additional ranges. As far as I can see this is the only problematic edge case.
I get an exception of
1, IP Address error: exceeds address size
inet.ipaddr.AddressValueException: 1, IP Address error: exceeds address size
at inet.ipaddr.format.standard.AddressDivisionGrouping.checkOverflow(AddressDivisionGrouping.java:1204)
at inet.ipaddr.ipv4.IPv4AddressSection.increment(IPv4AddressSection.java:1209)
at inet.ipaddr.ipv4.IPv4Address.increment(IPv4Address.java:717)
at inet.ipaddr.ipv4.IPv4Address.increment(IPv4Address.java:70)
at inet.ipaddr.IPAddressSeqRange.join(IPAddressSeqRange.java:668)
Provided is a test case that causes the exception
@Test
void bugExample() {
IPAddress minIpv4 = new IPAddressString("0.0.0.0").getAddress();
IPAddress maxIpv4 = new IPAddressString("255.255.255.255").getAddress();
IPAddress minIpv6 = new IPAddressString("0::0").getAddress();
IPAddress maxIpv6 = new IPAddressString("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").getAddress();
IPAddressSeqRange allIpv4 = minIpv4.spanWithRange(maxIpv4);
IPAddressSeqRange allIpv6 = minIpv6.spanWithRange(maxIpv6);
IPAddressSeqRange.join(allIpv4, allIpv6);
}