Fixed detection of overlong sequences (thanks Tommy!)
authorSam Lantinga <slouken@libsdl.org>
Fri, 05 Jul 2013 21:25:32 -0700
changeset 7349a96c85910792
parent 7348 50b6e7a26ba3
child 7350 302af2a46a66
Fixed detection of overlong sequences (thanks Tommy!)
src/stdlib/SDL_iconv.c
     1.1 --- a/src/stdlib/SDL_iconv.c	Fri Jul 05 01:31:02 2013 -0400
     1.2 +++ b/src/stdlib/SDL_iconv.c	Fri Jul 05 21:25:32 2013 -0700
     1.3 @@ -364,7 +364,7 @@
     1.4                           */
     1.5                          ch = UNKNOWN_UNICODE;
     1.6                      } else {
     1.7 -                        if (p[0] == 0xFC) {
     1.8 +                        if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) {
     1.9                              overlong = SDL_TRUE;
    1.10                          }
    1.11                          ch = (Uint32) (p[0] & 0x01);
    1.12 @@ -377,7 +377,7 @@
    1.13                           */
    1.14                          ch = UNKNOWN_UNICODE;
    1.15                      } else {
    1.16 -                        if (p[0] == 0xF8) {
    1.17 +                        if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) {
    1.18                              overlong = SDL_TRUE;
    1.19                          }
    1.20                          ch = (Uint32) (p[0] & 0x03);
    1.21 @@ -390,7 +390,7 @@
    1.22                           */
    1.23                          ch = UNKNOWN_UNICODE;
    1.24                      } else {
    1.25 -                        if (p[0] == 0xF0) {
    1.26 +                        if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) {
    1.27                              overlong = SDL_TRUE;
    1.28                          }
    1.29                          ch = (Uint32) (p[0] & 0x07);
    1.30 @@ -403,7 +403,7 @@
    1.31                           */
    1.32                          ch = UNKNOWN_UNICODE;
    1.33                      } else {
    1.34 -                        if (p[0] == 0xE0) {
    1.35 +                        if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) {
    1.36                              overlong = SDL_TRUE;
    1.37                          }
    1.38                          ch = (Uint32) (p[0] & 0x0F);