diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-05-18 00:06:03 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-05-18 00:06:03 +0000 |
commit | d48a2029915d779215178261f3a529b10acb992a (patch) | |
tree | b04f14927f916e66a80a30dc4ccd6deb242b787e /converter/pbm | |
parent | e165d1d85c5e1ee87540d2e326f97e4d539cfee0 (diff) | |
download | netpbm-mirror-d48a2029915d779215178261f3a529b10acb992a.tar.gz netpbm-mirror-d48a2029915d779215178261f3a529b10acb992a.tar.xz netpbm-mirror-d48a2029915d779215178261f3a529b10acb992a.zip |
Release 10.70.05
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2495 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/pbm')
-rw-r--r-- | converter/pbm/pbmtomacp.c | 19 | ||||
-rw-r--r-- | converter/pbm/pbmtomgr.c | 13 | ||||
-rw-r--r-- | converter/pbm/pbmtoxbm.c | 19 |
3 files changed, 37 insertions, 14 deletions
diff --git a/converter/pbm/pbmtomacp.c b/converter/pbm/pbmtomacp.c index 4dd819db..82ccce06 100644 --- a/converter/pbm/pbmtomacp.c +++ b/converter/pbm/pbmtomacp.c @@ -19,6 +19,8 @@ #define EQUAL 1 #define UNEQUAL 0 +#define MIN3(a,b,c) (MIN((MIN((a),(b))),(c))) + static void fillbits ARGS(( bit **bits, bit **bitsr, int top, int left, int bottom, int right )); static void writemacp ARGS(( bit **bits )); static int packit ARGS(( bit *pb, bit *bits )); @@ -101,23 +103,18 @@ char *argv[]; left = 0; if( rflg ) - { if( right - left >= MAX_COLS ) - right = left + MAX_COLS - 1; - } + right = MIN3( right, cols - 1, left + MAX_COLS - 1 ); else - right = ( left + MAX_COLS > cols ) ? ( cols - 1 ) : ( left + MAX_COLS - 1 ); + right = MIN( cols - 1, left + MAX_COLS - 1 ); if( !tflg ) top = 0; if( bflg ) - { if( bottom - top >= MAX_LINES ) - bottom = top + MAX_LINES - 1; - } + bottom = MIN3( bottom, rows - 1, top + MAX_LINES - 1); else - bottom = ( top + MAX_LINES > rows ) ? - ( rows - 1 ) : ( top + MAX_LINES - 1 ); - + bottom = MIN( rows - 1, top + MAX_LINES - 1 ); + if( right <= left || left < 0 || right - left + 1 > MAX_COLS ) pm_error("error in right (= %d) and/or left (=%d)",right,left ); if( bottom <= top || top < 0 || bottom - top + 1 > MAX_LINES ) @@ -219,7 +216,7 @@ packit( pb, bits ) save = *srcb++; charcount--; newcount = 1; - while( (*srcb == save) && charcount ) { + while( charcount && (*srcb == save) ) { srcb++; newcount++; charcount--; diff --git a/converter/pbm/pbmtomgr.c b/converter/pbm/pbmtomgr.c index 2ca7c7d0..d12e6635 100644 --- a/converter/pbm/pbmtomgr.c +++ b/converter/pbm/pbmtomgr.c @@ -6,9 +6,12 @@ ftp://sunsite.unc.edu/pub/Linux/apps/MGR/!INDEX.html */ +#include <assert.h> #include "pbm.h" #include "mgr.h" + + static void putinit(unsigned int const rows, unsigned int const cols) { @@ -16,6 +19,10 @@ putinit(unsigned int const rows, struct b_header head; size_t writtenCount; + /* Because of argument restrictions: maximum dimensions: */ + assert((rows & 0xfff) == rows); + assert((cols & 0xfff) == cols); + head.magic[0] = 'y'; head.magic[1] = 'z'; head.h_wide = ((cols >> 6) & 0x3f) + ' '; @@ -48,6 +55,8 @@ main(int argc, a multiple of 8, i.e. an integral number of packed bytes. */ const char * inputFileName; + unsigned int const maxDimension = 4095; + /* Dimensions are 2 characters of the header -- 12 bits */ pbm_init(&argc, argv); @@ -62,6 +71,10 @@ main(int argc, ifP = pm_openr(inputFileName); pbm_readpbminit(ifP, &cols, &rows, &format); + if (cols > maxDimension) + pm_error("Image width too large: %u (max: %u)", cols, maxDimension); + if (rows > maxDimension) + pm_error("Image height too large: %u (max: %u)", rows, maxDimension); bitrow = pbm_allocrow_packed(cols); bytesPerRow = pbm_packed_bytes(cols); diff --git a/converter/pbm/pbmtoxbm.c b/converter/pbm/pbmtoxbm.c index 2b59a17c..c6c4a9e6 100644 --- a/converter/pbm/pbmtoxbm.c +++ b/converter/pbm/pbmtoxbm.c @@ -249,7 +249,7 @@ puttermX10(void) { (i == 0) ? " " : "", itemBuff[i+1], itemBuff[i], - (i == itemCnt - 2) ? "};\n" : ","); + (i == itemCnt - 2) ? "" : ","); if (rc < 0) pm_error("Error writing end of X10 bitmap raster. " "printf() failed with errno %d (%s)", @@ -270,7 +270,7 @@ puttermX11(void) { rc = printf("%s0x%02x%s", (i == 0) ? " " : "", itemBuff[i], - (i == itemCnt - 1) ? "};\n" : ","); + (i == itemCnt - 1) ? "" : ","); if (rc < 0) pm_error("Error writing end of X11 bitmap raster. " @@ -297,6 +297,17 @@ putterm(void) { case X10: puttermX10(); break; case X11: puttermX11(); break; } + + { + int rc; + + rc = printf("};\n"); + + if (rc < 0) + pm_error("Error writing end of X11 bitmap raster. " + "printf() failed with errno %d (%s)", + errno, strerror(errno)); + } } @@ -339,7 +350,6 @@ convertRaster(FILE * const ifP, putinit(xbmVersion); bitrow = pbm_allocrow_packed(cols + padright); - bitrow[bitrowBytes-1] = 0; for (row = 0; row < rows; ++row) { int const bitrowInBytes = pbm_packed_bytes(cols); @@ -354,6 +364,9 @@ convertRaster(FILE * const ifP, bitrow[bitrowInBytes - 1] <<= padrightIn; } + if (padright >= 8) + bitrow[bitrowBytes-1] = 0x00; + for (i = 0; i < bitrowBytes; ++i) putitem(bitrow[i]); } |