From: Jens Axboe Date: Wed, 21 Mar 2007 09:32:54 +0000 (+0100) Subject: Catch too large memory allocations that cause size_t to wrap X-Git-Tag: fio-1.15~56 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=2b4ce34fac9f3031dc8606d6cd640c61a74d7df7 Catch too large memory allocations that cause size_t to wrap Signed-off-by: Jens Axboe --- diff --git a/fio.c b/fio.c index 92cb6573..29fecb79 100644 --- a/fio.c +++ b/fio.c @@ -588,6 +588,7 @@ static void fill_rand_buf(struct io_u *io_u, int max_bs) static int init_io_u(struct thread_data *td) { + unsigned long long buf_size; struct io_u *io_u; unsigned int max_bs; int i, max_units; @@ -599,7 +600,14 @@ static int init_io_u(struct thread_data *td) max_units = td->o.iodepth; max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]); - td->orig_buffer_size = page_mask + (max_bs * max_units); + buf_size = (unsigned long long) max_bs * (unsigned long long) max_units; + buf_size += page_mask; + if (buf_size != (size_t) buf_size) { + log_err("fio: IO memory too large. Reduce max_bs or iodepth\n"); + return 1; + } + + td->orig_buffer_size = buf_size; if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) td->orig_buffer_size = (td->orig_buffer_size + td->o.hugepage_size - 1) & ~(td->o.hugepage_size - 1);