]> granicus.if.org Git - php/commitdiff
SJIS-mac encoding conversion: Stop the carnage of innocent Unicode codepoints
authorAlex Dowad <alexinbeijing@gmail.com>
Sat, 19 Sep 2020 13:16:51 +0000 (15:16 +0200)
committerAlex Dowad <alexinbeijing@gmail.com>
Wed, 11 Nov 2020 09:18:58 +0000 (11:18 +0200)
When converting Unicode to MacJapanese, some special sequences of Unicode
codepoints are collapsed into a single SJIS character. When the implementation
sees a codepoint which *might* begin such a sequence, it is cached and examined
again after the next codepoint arrives.

If it turns out that it wasn't one of the 'special' sequences, then a 'fallback'
conversion table is consulted to convert the cached codepoint. Then we re-enter
the regular conversion code to convert the immediately following codepoint.
BUT, local variables need to be reinitialized properly when doing this!

Because the locals weren't reinitialized, the sad result was that some codepoints
would get chopped up into bit salad and emitted as something totally bogus
(which might not even be valid SJIS-mac text at all).

ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c

index 5214c429983910bb5701f66ef3452a06199b0a5e..78bf8e3671eb2d08c1c6bac6896661ad30242a39 100644 (file)
@@ -372,6 +372,7 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter)
                if (s2 <= 0 || s1 == -1) {
                        break;
                }
+               s1 = s2 = 0;
 
        case 0: