]> Cypherpunks.ru repositories - gostls13.git/commit
image: guard against NewXxx integer overflow
authorNigel Tao <nigeltao@golang.org>
Mon, 27 Apr 2020 23:32:00 +0000 (09:32 +1000)
committerNigel Tao <nigeltao@golang.org>
Wed, 29 Apr 2020 11:57:50 +0000 (11:57 +0000)
commit07d9ea64abf9f98c525155f4f22776512d4d835d
treeefb93c98cf6e1eadeefc617c07a0b908bac648e3
parent7250dd25400dbe1d38124f04ff5bd5a03f0c8e1c
image: guard against NewXxx integer overflow

Prior to this commit, NewXxx could panic when passed an image.Rectangle
with one of width or height being negative. But it might not panic if
both were negative, because (bpp * w * h) could still be positive. After
this commit, it will panic if both are negative.

With overflow, NewXxx might not have panicked if (bpp * w * h), the
length passed to "make([]uint8, length)", was still non-negative (after
truncation), but even if w and h were valid (non-negative), the overall
byte slice wasn't long enough. Iterating over the pixels would possibly
panic later with index out of bounds. This change moves the panic
earlier, closer to where the mistake is.

Change-Id: I011feb2d53515fc3f0fe72bb6c23b3953772c577
Reviewed-on: https://go-review.googlesource.com/c/go/+/230220
Reviewed-by: Rob Pike <r@golang.org>
src/image/geom.go
src/image/image.go
src/image/image_test.go
src/image/ycbcr.go