Guard against bogus zero width, height, bytes and allocation overflows. (cherry picked from commit 869dcd7b)