UTF-8: change upper limit from 0x1FFFFF to 0x10FFFF
authorJohn Marino <draco@marino.st>
Sun, 9 Aug 2015 00:12:35 +0000 (02:12 +0200)
committerJohn Marino <draco@marino.st>
Sun, 9 Aug 2015 00:12:35 +0000 (02:12 +0200)
In November 2003, RFC 3629 changed the upper bound from 0x7FFFFFFF (up to
6 bytes) to 0x10FFFF in order to match the constraints of UTF-16 encoding.
Last week, 5- and 6- bytes were considered illegal, now we also mark
a large portion of 4-byte sequences as illegal as well.

lib/libc/locale/utf8.c

index 88e0c62..ce18278 100644 (file)
@@ -145,18 +145,6 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
                        mask = 0x07;
                        want = 4;
                        lbound = 0x10000;
-#if 0
-               /* These would be illegal in the UTF-8 space */
-
-               } else if ((ch & 0xfc) == 0xf8) {
-                       mask = 0x03;
-                       want = 5;
-                       lbound = 0x200000;
-               } else if ((ch & 0xfe) == 0xfc) {
-                       mask = 0x01;
-                       want = 6;
-                       lbound = 0x4000000;
-#endif
                } else {
                        /*
                         * Malformed input; input is not UTF-8.
@@ -326,18 +314,9 @@ _UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
        } else if ((wc & ~0xffff) == 0) {
                lead = 0xe0;
                len = 3;
-       } else if ((wc & ~0x1fffff) == 0) {
+       } else if ((wc & ~0x10ffff) == 0) {
                lead = 0xf0;
                len = 4;
-#if 0
-       /* Again, 5 and 6 byte encodings are simply not permitted */
-       } else if ((wc & ~0x3ffffff) == 0) {
-               lead = 0xf8;
-               len = 5;
-       } else if ((wc & ~0x7fffffff) == 0) {
-               lead = 0xfc;
-               len = 6;
-#endif
        } else {
                errno = EILSEQ;
                return ((size_t)-1);