Fix possibly overflowing multiplications
Some possibly overflowing multiplication fixes, note that due to not being incredibly familiar with the code, these might be purely theoretical and not actually possible. Sorry for the noise, if that's the case.
Found with lgtm.com, there are a ton more but a lot of them
do seem purely theoretical, like for image width * height
which even if we have 16k some day would not cause an overflow.