Skip to content
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

Infinity loop at branchingFactorIPv4 function #12

Open
savely-krasovsky opened this issue Jul 4, 2021 · 0 comments
Open

Infinity loop at branchingFactorIPv4 function #12

savely-krasovsky opened this issue Jul 4, 2021 · 0 comments

Comments

@savely-krasovsky
Copy link

savely-krasovsky commented Jul 4, 2021

It seems like on some sets of prefixes (128.0.0.0/1 and 0.0.0.0/1 in my case), it causes infinity loop:

func branchingFactorIPv4(ps []Prefix) (int, bool) {
	var lastBF, lastN int
	base := ipToIPv4Int(ps[0].IP.Mask(ps[0].Mask))
	mask := ipMaskToIPv4Int(ps[0].Mask)
	l := ps[0].Len()
	for bf := 1; bf < IPv4PrefixLen; bf++ {
		n, nfull := 0, 1<<uint(bf)
		max := ipv4Int(1 << uint(bf))
		aggrMask := mask << uint(bf)
		for pat := ipv4Int(0); pat < max; pat++ {
			aggr := base&aggrMask | pat<<uint(IPv4PrefixLen-l)
			for _, p := range ps {
				i := ipToIPv4Int(p.IP)
				if aggr == i&mask {
					n++
				}
			}
		}
		if n < nfull {
			break
		}
		lastBF = bf
		lastN = n
	}
	n := 1 << uint(lastBF)
	return n, lastN >= n
}

After some calculation it causes panic:

runtime error: slice bounds out of range [:2147483648] with capacity 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant