You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using merge on an unsorted array of CIDR blocks and ran into this error for IPv6. I cannot reproduce the error in IPv4. I don't see a requirement in the documentation to sort the blocks before merging, so I believe it's a bug.
Minimal Reproduction
import{merge}from"cidr-tools";// Works, returns an array of two CIDR blocksmerge(['1:1:1:1::/128','1:1:1:2::/128',]);// Fails, throws a division by zero errormerge(['1:1:1:2::/128','1:1:1:1::/128',]);
Error
node_modules/cidr-tools/index.js:194
start = ((part.end / biggest) - 1n) * biggest;
^
RangeError: Division by zero
at subparts (node_modules/cidr-tools/index.js:194:28)
at merge (node_modules/cidr-tools/index.js:289:27)
Definitely a bug. The smallest numbers I could reproduce with is merge(["::2:0:0/128", "::1:0:0/128"]). At least safeguarding for division by zero does not fix it because the subparts function would recurse forever.
I added a workaround that pre-sorts the networks in merge which does seem to resolve it. It's definitely not the right fix as merge should work with any sorting, but a real fix is likely not so trivial and that's why I'll keep this issue open.
I am using
merge
on an unsorted array of CIDR blocks and ran into this error for IPv6. I cannot reproduce the error in IPv4. I don't see a requirement in the documentation to sort the blocks before merging, so I believe it's a bug.Minimal Reproduction
Error
Source Line of Code
cidr-tools/index.js
Line 194 in 0ce9d7f
Versions
The text was updated successfully, but these errors were encountered: