Grow: avoid overflow in compute_backup_blocks()

With a chunk size of 16Meg and data drive count of 8,
this calculate can easily overflow the 'int' type that
is used for the multiplications.
So force it to use "long" instead.

Reported-and-tested-by: Ed Spiridonov <edo.rus@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
NeilBrown 2018-12-06 10:35:41 +11:00 committed by Jes Sorensen
parent 563ac10865
commit 085df42259
1 changed files with 2 additions and 1 deletions

3
Grow.c
View File

@ -1196,7 +1196,8 @@ unsigned long compute_backup_blocks(int nchunk, int ochunk,
/* Find GCD */
a = GCD(a, b);
/* LCM == product / GCD */
blocks = (ochunk/512) * (nchunk/512) * odata * ndata / a;
blocks = (unsigned long)(ochunk/512) * (unsigned long)(nchunk/512) *
odata * ndata / a;
return blocks;
}