Seeing the discussion of strings.Repeat and invalid inputs in another
thread, I noticed a couple of bugs. One I have reported -
https://github.com/golang/go/issues/16237

The other I'm not sure if it's worth a report. Here's the source for
bytes.repeat:

   391  func Repeat(b []byte, count int) []byte {   392         nb :=
make([]byte, len(b)*count)   393                bp := copy(nb, b)   394         
for bp <
len(nb) {   395                 copy(nb[bp:], nb[:bp])   396                    
bp *= 2   397           }
398             return nb   399 }

Here, if len(nb) is small enough to fit in an int, but large enough that 2
* nb overflows an int, then there may be some cases where bp < len(nb) but
2 * bp overflows. Most likely leading to a panic from slicing with negative
indices.

But this can only happen if the allocation of len(nb) bytes succeeds. With
64 bit ints, that's ridiculous (this year, anyway). With 32 bit ints - can
an allocation of a gigabyte succeed? I suppose that depends on OS details.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to