rEFIt_UEFI/libeg/lodepng.cpp
/*Safely checks whether size_t overflow can be caused due to amount of pixels.
This check is overcautious rather than precise. If this check indicates no overflow,
you can safely compute in a size_t (but not an unsigned):
-(size_t)w * (size_t)h * 8
-amount of bytes in IDAT (including filter, padding and Adam7 bytes)
-amount of bytes in raw color model
Returns 1 if overflow possible, 0 if not.
*/
Safely checks whether size_t overflow can be caused due to amount of pixels.
This check is overcautious rather than precise. If this check indicates no overflow,
you can safely compute in a size_t (but not an unsigned):
(size_t)w * (size_t)h * 8
amount of bytes in IDAT (including filter, padding and Adam7 bytes)
amount of bytes in raw color model
Returns 1 if overflow possible, 0 if not.
Safely checks whether size_t overflow can be caused due to amount of pixels . This check is overcautious rather than precise . If this check indicates no overflow you can safely compute in a size_t ( but not an unsigned ) : ( size_t ) w * ( size_t ) h * 8 amount of bytes in IDAT ( including filter padding and Adam7 bytes ) amount of bytes in raw color model Returns 1 if overflow possible 0 if not .
static int lodepng_pixel_overflow(unsigned w, unsigned h,
                                  const LodePNGColorMode* pngcolor, const LodePNGColorMode* rawcolor) {
  size_t bpp = LODEPNG_MAX(lodepng_get_bpp(pngcolor), lodepng_get_bpp(rawcolor));
  size_t numpixels, total;
  size_t line; 
  if(lodepng_mulofl((size_t)w, (size_t)h, &numpixels)) return 1;
  if(lodepng_mulofl(numpixels, 8, &total)) return 1; 
  if(lodepng_mulofl((size_t)(w / 8u), bpp, &line)) return 1;
  if(lodepng_addofl(line, ((w & 7u) * bpp + 7u) / 8u, &line)) return 1;
  if(lodepng_addofl(line, 5, &line)) return 1; 
  if(lodepng_mulofl(line, h, &total)) return 1; 
  return 0; 
}
static int lodepng_pixel_overflow ( unsigned w , unsigned h , const LodePNGColorMode * pngcolor , const LodePNGColorMode * rawcolor ) { size_t bpp = LODEPNG_MAX ( lodepng_get_bpp ( pngcolor ) , lodepng_get_bpp ( rawcolor ) ) ; size_t numpixels , total ; size_t line ; if ( lodepng_mulofl ( ( size_t ) w , ( size_t ) h , & numpixels ) ) return 1 ; if ( lodepng_mulofl ( numpixels , 8 , & total ) ) return 1 ; if ( lodepng_mulofl ( ( size_t ) ( w / 8u ) , bpp , & line ) ) return 1 ; if ( lodepng_addofl ( line , ( ( w & 7u ) * bpp + 7u ) / 8u , & line ) ) return 1 ; if ( lodepng_addofl ( line , 5 , & line ) ) return 1 ; if ( lodepng_mulofl ( line , h , & total ) ) return 1 ; return 0 ; }
Safely checks whether size_t overflow can be caused due to amount of pixels.
Safely checks whether size_t overflow can be caused due to amount of pixels .
/* bytes per line in worst case */ /* bit pointer with 8-bit color, or 8 bytes per channel color */ /* Bytes per scanline with the expression "(w / 8u) * bpp) + ((w & 7u) * bpp + 7u) / 8u" */ /* 5 bytes overhead per line: 1 filterbyte, 4 for Adam7 worst case */ /* Total bytes in worst case */ /* no overflow */