share/ipld: newProofCollector should use bits.Len instead of math.Log2 just in case #3852
Labels
bug
Something isn't working
external
Issues created by non node team members
good first issue
Good for newcomers
Celestia Node version
d7d2db8
OS
darwin
Install tools
No response
Others
No response
Steps to reproduce it
Read through
celestia-node/share/ipld/proof_collector.go
Line 17 in d7d2db8
It isn't a problem nor an attack vector as we deemed offline but if a caller passed in a max shard size of 0, that code could cause a runtime panic because of this result:
log(0) = INFINITY and in Go that's represented by -INF or +INF whichever is implementation defined
which when converted to an integer is the smallest negative value which when passed into
make([]T, -value)
Expected result
Zero value allocated for negative values or no crash
Actual result
A runtime panic
Relevant log output
No response
Is the node "stuck"? Has it stopped syncing?
No
Notes
Remedy
We can safely instead use math/bits.Len64 which even if had a negative number would have a maximum of 64 values
and here is a clear exhibit
https://go.dev/play/p/IlSf1wlm3nT
which prints out
and is guaranteed never to panic, because bits.Len64(uint64(positive of negative int)) = [0, 63]
but math.Log2(float64(positive or negative int)) = [-9223372036854775808, 63]
Kindly cc-ing @Wondertan
The text was updated successfully, but these errors were encountered: