diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-06-19 03:00:26 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-06-19 03:00:26 +0000 |
commit | f9796103427dcfea789675aa0a5676cce8da6c16 (patch) | |
tree | 426d9f8516f65c6c19d9ac6a135126e79cf23790 /converter/other/pnmtopalm | |
parent | ebb3762e6dfb619c1345b67c5960eaa873d9c0a8 (diff) | |
download | netpbm-mirror-f9796103427dcfea789675aa0a5676cce8da6c16.tar.gz netpbm-mirror-f9796103427dcfea789675aa0a5676cce8da6c16.tar.xz netpbm-mirror-f9796103427dcfea789675aa0a5676cce8da6c16.zip |
Fix packbits decoder
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2556 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/pnmtopalm')
-rw-r--r-- | converter/other/pnmtopalm/palmtopnm.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/converter/other/pnmtopalm/palmtopnm.c b/converter/other/pnmtopalm/palmtopnm.c index 41fc50af..00aa35e4 100644 --- a/converter/other/pnmtopalm/palmtopnm.c +++ b/converter/other/pnmtopalm/palmtopnm.c @@ -820,15 +820,16 @@ readPackBitsRow16(FILE * const ifP, unsigned int k; unsigned short inval; pm_readlittleshortu(ifP, &inval); - for (k = 0; (k < runlength) && (j + k + 1 < bytesPerRow); k += 2) { - memcpy(palmrow + j + k, &inval, 2); + if (j + runlength <= bytesPerRow) { + for (k = 0; k < runlength; k += 2) + memcpy(palmrow + j + k, &inval, 2); } j += runlength; } else { /* We just read the stream of shorts as a stream of chars */ unsigned int const nonrunlength = (incount + 1) * 2; unsigned int k; - for (k = 0; (k < nonrunlength) && (j + k < bytesPerRow); ++k) { + for (k = 0; (k < nonrunlength) && (j + k <= bytesPerRow); ++k) { unsigned char inval; pm_readcharu(ifP, &inval); palmrow[j + k] = inval; @@ -860,13 +861,13 @@ readPackBitsRow(FILE * const ifP, unsigned int const runlength = -incount + 1; unsigned char inval; pm_readcharu(ifP, &inval); - if (j + runlength < bytesPerRow) + if (j + runlength <= bytesPerRow) memset(palmrow + j, inval, runlength); j += runlength; } else { unsigned int const nonrunlength = incount + 1; unsigned int k; - for (k = 0; k < nonrunlength && j + k < bytesPerRow; ++k) { + for (k = 0; k < nonrunlength && j + k <= bytesPerRow; ++k) { unsigned char inval; pm_readcharu(ifP, &inval); palmrow[j + k] = inval; |