diff options
Diffstat (limited to 'converter/pbm/pbmtomgr.c')
-rw-r--r-- | converter/pbm/pbmtomgr.c | 13 |
1 files changed, 13 insertions, 0 deletions
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); |