avoid potential int32 overflows in multiply_ms()

This commit is contained in:
Young_X 2018-09-08 14:46:27 +08:00
parent f1b94e8a3b
commit 6da1fb3f64

View File

@ -70,15 +70,16 @@ BadPPM(char* file)
exit(-2); exit(-2);
} }
#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
static tmsize_t static tmsize_t
multiply_ms(tmsize_t m1, tmsize_t m2) multiply_ms(tmsize_t m1, tmsize_t m2)
{ {
tmsize_t bytes = m1 * m2; if( m1 == 0 || m2 > TIFF_TMSIZE_T_MAX / m1 )
return 0;
if (m1 && bytes / m1 != m2) return m1 * m2;
bytes = 0;
return bytes;
} }
int int