Fixed detection of overlong sequences (thanks Tommy!)
authorSam Lantinga <slouken@libsdl.org>
Fri, 05 Jul 2013 21:25:32 -0700
changeset 7349 a96c85910792
parent 7348 50b6e7a26ba3
child 7350 302af2a46a66
Fixed detection of overlong sequences (thanks Tommy!)
src/stdlib/SDL_iconv.c
--- a/src/stdlib/SDL_iconv.c	Fri Jul 05 01:31:02 2013 -0400
+++ b/src/stdlib/SDL_iconv.c	Fri Jul 05 21:25:32 2013 -0700
@@ -364,7 +364,7 @@
                          */
                         ch = UNKNOWN_UNICODE;
                     } else {
-                        if (p[0] == 0xFC) {
+                        if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) {
                             overlong = SDL_TRUE;
                         }
                         ch = (Uint32) (p[0] & 0x01);
@@ -377,7 +377,7 @@
                          */
                         ch = UNKNOWN_UNICODE;
                     } else {
-                        if (p[0] == 0xF8) {
+                        if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) {
                             overlong = SDL_TRUE;
                         }
                         ch = (Uint32) (p[0] & 0x03);
@@ -390,7 +390,7 @@
                          */
                         ch = UNKNOWN_UNICODE;
                     } else {
-                        if (p[0] == 0xF0) {
+                        if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) {
                             overlong = SDL_TRUE;
                         }
                         ch = (Uint32) (p[0] & 0x07);
@@ -403,7 +403,7 @@
                          */
                         ch = UNKNOWN_UNICODE;
                     } else {
-                        if (p[0] == 0xE0) {
+                        if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) {
                             overlong = SDL_TRUE;
                         }
                         ch = (Uint32) (p[0] & 0x0F);