|
|
17783b |
From b64713005e6110c36265750435cfa641d3a9281f Mon Sep 17 00:00:00 2001
|
|
|
17783b |
From: Thomas Bernard <miniupnp@free.fr>
|
|
|
17783b |
Date: Mon, 11 Feb 2019 23:08:25 +0100
|
|
|
17783b |
Subject: [PATCH] tiffcrop.c: fix invertImage() for bps 2 and 4
|
|
|
17783b |
|
|
|
17783b |
too much bytes were processed, causing a heap buffer overrun
|
|
|
17783b |
http://bugzilla.maptools.org/show_bug.cgi?id=2831
|
|
|
17783b |
the loop counter must be
|
|
|
17783b |
for (col = 0; col < width; col += 8 / bps)
|
|
|
17783b |
|
|
|
17783b |
Also the values were not properly calculated. It should be
|
|
|
17783b |
255-x, 15-x, 3-x for bps 8, 4, 2.
|
|
|
17783b |
|
|
|
17783b |
But anyway it is easyer to invert all bits as 255-x = ~x, etc.
|
|
|
17783b |
(substracting from a binary number composed of all 1 is like inverting
|
|
|
17783b |
the bits)
|
|
|
17783b |
---
|
|
|
17783b |
tools/tiffcrop.c | 37 ++++++-------------------------------
|
|
|
17783b |
1 file changed, 6 insertions(+), 31 deletions(-)
|
|
|
17783b |
|
|
|
17783b |
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
|
|
|
17783b |
index 3862b1c..a612914 100644
|
|
|
17783b |
--- a/tools/tiffcrop.c
|
|
|
17783b |
+++ b/tools/tiffcrop.c
|
|
|
17783b |
@@ -9142,7 +9142,6 @@ static int
|
|
|
17783b |
invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 length, unsigned char *work_buff)
|
|
|
17783b |
{
|
|
|
17783b |
uint32 row, col;
|
|
|
17783b |
- unsigned char bytebuff1, bytebuff2, bytebuff3, bytebuff4;
|
|
|
17783b |
unsigned char *src;
|
|
|
17783b |
uint16 *src_uint16;
|
|
|
17783b |
uint32 *src_uint32;
|
|
|
17783b |
@@ -9172,7 +9171,7 @@ invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 len
|
|
|
17783b |
for (row = 0; row < length; row++)
|
|
|
17783b |
for (col = 0; col < width; col++)
|
|
|
17783b |
{
|
|
|
17783b |
- *src_uint32 = (uint32)0xFFFFFFFF - *src_uint32;
|
|
|
17783b |
+ *src_uint32 = ~(*src_uint32);
|
|
|
17783b |
src_uint32++;
|
|
|
17783b |
}
|
|
|
17783b |
break;
|
|
|
17783b |
@@ -9180,39 +9179,15 @@ invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 len
|
|
|
17783b |
for (row = 0; row < length; row++)
|
|
|
17783b |
for (col = 0; col < width; col++)
|
|
|
17783b |
{
|
|
|
17783b |
- *src_uint16 = (uint16)0xFFFF - *src_uint16;
|
|
|
17783b |
+ *src_uint16 = ~(*src_uint16);
|
|
|
17783b |
src_uint16++;
|
|
|
17783b |
}
|
|
|
17783b |
break;
|
|
|
17783b |
- case 8: for (row = 0; row < length; row++)
|
|
|
17783b |
- for (col = 0; col < width; col++)
|
|
|
17783b |
- {
|
|
|
17783b |
- *src = (uint8)255 - *src;
|
|
|
17783b |
- src++;
|
|
|
17783b |
- }
|
|
|
17783b |
- break;
|
|
|
17783b |
- case 4: for (row = 0; row < length; row++)
|
|
|
17783b |
- for (col = 0; col < width; col++)
|
|
|
17783b |
- {
|
|
|
17783b |
- bytebuff1 = 16 - (uint8)(*src & 240 >> 4);
|
|
|
17783b |
- bytebuff2 = 16 - (*src & 15);
|
|
|
17783b |
- *src = bytebuff1 << 4 & bytebuff2;
|
|
|
17783b |
- src++;
|
|
|
17783b |
- }
|
|
|
17783b |
- break;
|
|
|
17783b |
- case 2: for (row = 0; row < length; row++)
|
|
|
17783b |
- for (col = 0; col < width; col++)
|
|
|
17783b |
- {
|
|
|
17783b |
- bytebuff1 = 4 - (uint8)(*src & 192 >> 6);
|
|
|
17783b |
- bytebuff2 = 4 - (uint8)(*src & 48 >> 4);
|
|
|
17783b |
- bytebuff3 = 4 - (uint8)(*src & 12 >> 2);
|
|
|
17783b |
- bytebuff4 = 4 - (uint8)(*src & 3);
|
|
|
17783b |
- *src = (bytebuff1 << 6) || (bytebuff2 << 4) || (bytebuff3 << 2) || bytebuff4;
|
|
|
17783b |
- src++;
|
|
|
17783b |
- }
|
|
|
17783b |
- break;
|
|
|
17783b |
+ case 8:
|
|
|
17783b |
+ case 4:
|
|
|
17783b |
+ case 2:
|
|
|
17783b |
case 1: for (row = 0; row < length; row++)
|
|
|
17783b |
- for (col = 0; col < width; col += 8 /(spp * bps))
|
|
|
17783b |
+ for (col = 0; col < width; col += 8 / bps)
|
|
|
17783b |
{
|
|
|
17783b |
*src = ~(*src);
|
|
|
17783b |
src++;
|
|
|
17783b |
--
|
|
|
17783b |
2.32.0
|
|
|
17783b |
|