Add some checks to avoid integer overflow for cubes
Description
This can happen if the product of the different dimensions of the cube is larger than 2^31.
Checklist
-
I have checked that my code follows the Octopus coding standards -
I have added tests for all the new features added in this request.