diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-11-07 01:33:26 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2021-11-07 01:33:26 +0000 |
commit | 42efa67c47521596088768d82f5665b15d03d6bf (patch) | |
tree | 358e75c107ff9ef1a45e3f4a15085d1f3f7a7a42 /converter/pbm/ybmtopbm.c | |
parent | 109fb3ec30eaca9ce3427d58a2b8fb1c038a7c4f (diff) | |
download | netpbm-mirror-42efa67c47521596088768d82f5665b15d03d6bf.tar.gz netpbm-mirror-42efa67c47521596088768d82f5665b15d03d6bf.tar.xz netpbm-mirror-42efa67c47521596088768d82f5665b15d03d6bf.zip |
fix arithmetic overflows
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4177 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/pbm/ybmtopbm.c')
-rw-r--r-- | converter/pbm/ybmtopbm.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c index 2a429086..36f2dee7 100644 --- a/converter/pbm/ybmtopbm.c +++ b/converter/pbm/ybmtopbm.c @@ -19,45 +19,48 @@ static short const ybmMagic = ( ( '!' << 8 ) | '!' ); static void -getinit(FILE * const ifP, - short * const colsP, - short * const rowsP, - short * const depthP) { +getinit(FILE * const ifP, + unsigned int * const colsP, + unsigned int * const rowsP, + int * const depthP) { - short magic; + short int magic; + short int cols, rows; int rc; rc = pm_readbigshort(ifP, &magic); if (rc == -1) pm_error("EOF / read error"); - - if (magic != ybmMagic) + else if (magic != ybmMagic) pm_error("bad magic number in YBM file"); - rc = pm_readbigshort(ifP, colsP); + rc = pm_readbigshort(ifP, &cols); if (rc == -1 ) pm_error("EOF / read error"); + else if (cols <= 0) + pm_error("invalid width value in YBM file"); - rc = pm_readbigshort(ifP, rowsP); + rc = pm_readbigshort(ifP, &rows); if (rc == -1) pm_error("EOF / read error"); + else if (rows <= 0) + pm_error("invalid height value in YBM file"); + *colsP = (unsigned int) cols; + *rowsP = (unsigned int) rows; *depthP = 1; } - - - int main(int argc, const char * argv[]) { FILE * ifP; bit * bitrow; - short rows, cols; + unsigned int rows, cols; unsigned int row; - short depth; + int depth; const char * inputFile; pm_proginit(&argc, argv); @@ -76,8 +79,8 @@ main(int argc, const char * argv[]) { getinit(ifP, &cols, &rows, &depth); if (depth != 1) - pm_error("YBM file has depth of %u, must be 1", (unsigned)depth); - + pm_error("YBM file has depth of %u, must be 1", (unsigned int) depth); + pbm_writepbminit(stdout, cols, rows, 0); bitrow = pbm_allocrow_packed(cols + 8); @@ -92,7 +95,7 @@ main(int argc, const char * argv[]) { for (i = 0; i < itemCt; ++i) { short int item; pm_readbigshort(ifP, &item); - itemrow[i] = (uint16_t) item; + itemrow[i] = (uint16_t) item; } for (i = 0; i < pbm_packed_bytes(cols); ++i) |