Skip to contentSkip to conversation

vnc-enc-tight: fix off-by-one bug

PATCH In review Herongguang (Stephen) 2 participants 2 messages Jul 12, 2016 – Jul 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vnc-enc-tight: fix off-by-one bug

In tight_encode_indexed_rect32, buf(or src)’s size is count. In for loop, the logic is supposed to be that i is an index into src, i should be incremented when incrementing src.

This is broken when src is incremented but i is not before while loop, resulting in off-by-one bug in while loop.

---
 ui/vnc-enc-tight.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ui/vnc-enc-tight.c +2 -1
index e5cba0e..678c5df 100644
@@ -461,9 +461,10 @@ static int tight_fill_palette(VncState *vs, int x, int y,
                                                                         \
         src = (uint##bpp##_t *) buf;                                    \
                                                                         \
-        for (i = 0; i < count; i++) {                                   \
+        for (i = 0; i < count; ) {                                      \
                                                                         \
             rgb = *src++;                                               \
+            i++;                                                        \
             rep = 0;                                                    \
             while (i < count && *src == rgb) {                          \
                 rep++, src++, i++;                                      \
Signature · 1 line
1.8.3.4
#1 lore raw
Quoted 8 lines · Herongguang (Stephen)

In tight_encode_indexed_rect32, buf(or src)’s size is count. In for loop, the logic is supposed to be that i is an index into src, i should be incremented when incrementing src.

This is broken when src is incremented but i is not before while loop, resulting in off-by-one bug in while loop.

Added to vnc queue.

Patch is whitespace mangled, had to use "patch --ignore-whitespace" to get it applied. Can you please use 'git send-email' to send patches in the future? That is the best way to avoid your mail client breaking patches.

thanks,
Gerd