]> granicus.if.org Git - php/commitdiff
Do not pass invalid ISO-8859-{3,6,7,8} characters through silently
authorAlex Dowad <alexinbeijing@gmail.com>
Fri, 16 Oct 2020 20:03:27 +0000 (22:03 +0200)
committerAlex Dowad <alexinbeijing@gmail.com>
Fri, 16 Oct 2020 20:17:45 +0000 (22:17 +0200)
mbstring has a bad habit of passing invalid characters through silently
when converting to the same (or a "compatible") encoding.

For example, if you give it an invalid JIS X 0208 kuten code encoded with SJIS,
and try to convert that to EUC-JP, mbstring will just quietly re-encode the
invalid code in the EUC-JP representation.

At the same, some parts of the code (like `mb_check_encoding`) assume that
invalid characters will be treated as... well, invalid. Let's unbreak things
by actually catching errors and reporting them, instead of swallowing them.

ext/mbstring/libmbfl/filters/mbfilter_iso8859_3.c
ext/mbstring/libmbfl/filters/mbfilter_iso8859_6.c
ext/mbstring/libmbfl/filters/mbfilter_iso8859_7.c
ext/mbstring/libmbfl/filters/mbfilter_iso8859_8.c

index 0c061055f89076b5a659a5fca843390d0829f7c2..5cd3bfce1d9fd422c53a79d0f2b49240e9a9bd13 100644 (file)
@@ -121,9 +121,6 @@ int mbfl_filt_conv_wchar_8859_3(int c, mbfl_convert_filter *filter)
                        }
                        n--;
                }
-               if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_8859_3) {
-                       s = c & MBFL_WCSPLANE_MASK;
-               }
        }
 
        if (s >= 0) {
index ead2b49e0b75a2f5d64266b1b4d91484f3484799..8b1fc4bbadd60a7a5fef54b67e6d1ba13a7895a4 100644 (file)
@@ -121,9 +121,6 @@ int mbfl_filt_conv_wchar_8859_6(int c, mbfl_convert_filter *filter)
                        }
                        n--;
                }
-               if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_8859_6) {
-                       s = c & MBFL_WCSPLANE_MASK;
-               }
        }
 
        if (s >= 0) {
index 63ae85e84e33f2abc665946f6624bfa6eb1346b9..e87ae0ec36dbc35ef4087e2469b233d77299bb4a 100644 (file)
@@ -121,9 +121,6 @@ int mbfl_filt_conv_wchar_8859_7(int c, mbfl_convert_filter *filter)
                        }
                        n--;
                }
-               if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_8859_7) {
-                       s = c & MBFL_WCSPLANE_MASK;
-               }
        }
 
        if (s >= 0) {
index 36c967405bb26f156eb2886d9016c054a8b651cf..3436d8d3ead80184b3574308d2687fe70c78fb76 100644 (file)
@@ -120,9 +120,6 @@ int mbfl_filt_conv_wchar_8859_8(int c, mbfl_convert_filter *filter)
                        }
                        n--;
                }
-               if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_8859_8) {
-                       s = c & MBFL_WCSPLANE_MASK;
-               }
        }
 
        if (s >= 0) {