Avoid an infinite loop on broken utf16.
authorRodrigo Kumpera <kumpera@gmail.com>
Sun, 13 Feb 2011 18:48:01 +0000 (19:48 +0100)
committerRodrigo Kumpera <kumpera@gmail.com>
Sun, 13 Feb 2011 18:48:01 +0000 (19:48 +0100)
* gutf8.c (g_utf16_to_utf8): Increase the input counter
when encountering broken surrogates head or tails to
make sure we don't end in an infinite loop.

eglib/src/gutf8.c

index cb1776107ba4ba377bd254e3eceb7c4122fa1b2d..65ffbcd7fa4c13ee345ebc4e39954f4b39eedc91 100644 (file)
@@ -338,6 +338,7 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
                        } else {
                                surrogate = 0;
                                /* invalid surrogate pair */
+                               ++in_pos;
                                continue;
                        }
                } else {
@@ -354,6 +355,7 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
                        else if (ch >= 0xD800 && ch <= 0xDBFF)
                                surrogate = ch;
                        else if (ch >= 0xDC00 && ch <= 0xDFFF) {
+                               ++in_pos;
                                /* invalid surrogate pair */
                                continue;
                        }