On Mon, Jan 29, 2024 at 08:31:51AM +0100, Christoph Hellwig wrote: > Check the 32-bit limits using sizeof instead of cpp ifdefs so that we > can get rid of BITS_PER_LONG. > > Signed-off-by: Christoph Hellwig <hch@xxxxxx> > --- > repair/bmap.c | 23 +++++++++++++++-------- > repair/bmap.h | 13 ------------- > 2 files changed, 15 insertions(+), 21 deletions(-) > > diff --git a/repair/bmap.c b/repair/bmap.c > index cd1a8b07b..d1b2faaec 100644 > --- a/repair/bmap.c > +++ b/repair/bmap.c > @@ -22,6 +22,15 @@ > pthread_key_t dblkmap_key; > pthread_key_t ablkmap_key; > > +/* > + * For 32 bit platforms, we are limited to extent arrays of 2^31 bytes, which > + * limits the number of extents in an inode we can check. If we don't limit the > + * valid range, we can overflow the BLKMAP_SIZE() calculation and allocate less > + * memory than we think we needed, and hence walk off the end of the array and > + * corrupt memory. > + */ > +#define BLKMAP_NEXTS32_MAX ((INT_MAX / sizeof(bmap_ext_t)) - 1) > + > blkmap_t * > blkmap_alloc( > xfs_extnum_t nex, > @@ -35,8 +44,7 @@ blkmap_alloc( > if (nex < 1) > nex = 1; > > -#if (BITS_PER_LONG == 32) /* on 64-bit platforms this is never true */ > - if (nex > BLKMAP_NEXTS_MAX) { > + if (sizeof(long) == 32 && nex > BLKMAP_NEXTS32_MAX) { That's a really, really big long. sizeof(long) = 4, perhaps? -Dave. -- Dave Chinner david@xxxxxxxxxxxxx