vnc-enc-tight: fix off-by-one bug
authorHerongguang (Stephen) <herongguang.he@huawei.com>
Tue, 12 Jul 2016 09:31:23 +0000 (17:31 +0800)
committerGerd Hoffmann <kraxel@redhat.com>
Fri, 15 Jul 2016 10:11:55 +0000 (12:11 +0200)
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.

Signed-off-by: He Rongguang <herongguang.he@huawei.com>
Message-id: 5784B8EB.7010008@huawei.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ui/vnc-enc-tight.c

index b8581dd2e997f20c359a131647bf0ceaac8a9714..877c09319d8146accd1421e93a7de65bbbdc27c8 100644 (file)
@@ -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++;                                      \