diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2017-03-28 15:34:36 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2017-03-28 15:34:36 +0000 |
commit | ca561223546a7e8acd055d5b2114869dd88f5114 (patch) | |
tree | 79a54d551eac6df794c539d8b8924aab217a1941 /converter/other/bmptopnm.c | |
parent | 8b32628b4c65cdd2b09e877150bbc4bcdd9b6ba7 (diff) | |
download | netpbm-mirror-ca561223546a7e8acd055d5b2114869dd88f5114.tar.gz netpbm-mirror-ca561223546a7e8acd055d5b2114869dd88f5114.tar.xz netpbm-mirror-ca561223546a7e8acd055d5b2114869dd88f5114.zip |
Copy Development as new Advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2932 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/bmptopnm.c')
-rw-r--r-- | converter/other/bmptopnm.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c index c39b4fd7..54868364 100644 --- a/converter/other/bmptopnm.c +++ b/converter/other/bmptopnm.c @@ -695,6 +695,13 @@ bmpReadinfoheader(FILE * const ifP, *errorP = NULL; *bytesReadP = cInfoHeaderSize; } + /* Part of our anti-arithmetic overflow strategy is to make sure height + and width always fit in 16 bits, so they can be multiplied together. + This shouldn't be a problem, since they come from 16 bit fields in + the BMP info header. + */ + assert(headerP->cols < (1<<16)); + assert(headerP->rows < (1<<16)); } @@ -1204,6 +1211,9 @@ bmpReadraster(FILE * const ifP, */ unsigned char ** bmpRaster; + assert(cols < (1<<16)); + assert(bytesPerRow < (1<<16)); + bmpRaster = allocBmpRaster(rows, bytesPerRow); *bytesReadP = 0; @@ -1456,8 +1466,8 @@ readBmp(FILE * const ifP, static void writeRasterGen(unsigned char ** const bmpRaster, - int const cols, - int const rows, + unsigned int const cols, + unsigned int const rows, int const format, unsigned int const cBitCount, struct pixelformat const pixelformat, @@ -1492,8 +1502,8 @@ writeRasterGen(unsigned char ** const bmpRaster, static void writeRasterPbm(unsigned char ** const bmpRaster, - int const cols, - int const rows, + unsigned int const cols, + unsigned int const rows, xel const colormap[]) { /*---------------------------------------------------------------------------- Write the PBM raster to Standard Output corresponding to the raw BMP @@ -1510,9 +1520,9 @@ writeRasterPbm(unsigned char ** const bmpRaster, We destroy *bmpRaster as a side effect. -----------------------------------------------------------------------------*/ - unsigned int const colChars = pbm_packed_bytes(cols); + unsigned int const colCharCt = pbm_packed_bytes(cols); - int row; + unsigned int row; enum colorFormat {BlackWhite, WhiteBlack}; enum colorFormat colorformat; @@ -1521,12 +1531,12 @@ writeRasterPbm(unsigned char ** const bmpRaster, else colorformat = BlackWhite; - for (row=0; row < rows; ++row){ + for (row = 0; row < rows; ++row){ unsigned char * const bitrow = bmpRaster[row]; if (colorformat == BlackWhite) { unsigned int i; - for (i = 0; i < colChars; ++i) + for (i = 0; i < colCharCt; ++i) bitrow[i] = ~bitrow[i]; /* flip all pixels */ } @@ -1550,7 +1560,7 @@ main(int argc, const char ** argv) { and gray. */ int cols, rows; - unsigned char **bmpRaster; + unsigned char ** bmpRaster; /* The raster part of the BMP image, as a row x column array, with each element being a raw byte from the BMP raster. Note that bmpRaster[0] is really Row 0 -- the top row of the image, even |