-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(ec2-alpha): rangesOverlap utility function is wrong #32145
Comments
rangesOverlap() utility function appears to return the result of expression Using the below example shared by user: // example
rangesOverlap(
["10.0.0.0", "10.0.15.255"], // 10.0.0.0/20
["10.0.128.0", "10.0.143.255"] // 10.0.128.0/20
) start2 is Perhaps the logic in rangesOverlap() utility function needs to be revisited. https://github.com/ip-num/ip-num is a TypeScript library for working with IPv4, IPv6 and ASN numbers. Some articles propose using below logic using this library: import { IPv4, IPv6 } from "ip-num";
function rangeOverlap(range1Start: string, range1End: string, range2Start: string, range2End: string): boolean {
const isIPv6 = IPv6.isValid(range1Start);
if (isIPv6) {
const start1 = IPv6.fromHexadecimalString(range1Start);
const end1 = IPv6.fromHexadecimalString(range1End);
const start2 = IPv6.fromHexadecimalString(range2Start);
const end2 = IPv6.fromHexadecimalString(range2End);
return start1.isLessThanOrEqualTo(end2) && start2.isLessThanOrEqualTo(end1);
} else {
const start1 = IPv4.fromDecimalDottedString(range1Start);
const end1 = IPv4.fromDecimalDottedString(range1End);
const start2 = IPv4.fromDecimalDottedString(range2Start);
const end2 = IPv4.fromDecimalDottedString(range2End);
return start1.isLessThanOrEqualTo(end2) && start2.isLessThanOrEqualTo(end1);
}
} |
I'd like to try fixing this |
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
rangesOverlap uses string comparison to determine overlap, which I believe is incorrect.
The above example should return false, but it returns true. Double checked some online tool to confirm that the cidrs do not actually overlap (https://cidrclash.com/clash-results).
Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
rangesOverlap implements proper cidr comparison
Current Behavior
Implementation is incorrect
Reproduction Steps
See description
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.167.0-alpha.0
Framework Version
No response
Node.js Version
22
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: