Fix some errors with handling invalid sequences in the EUC-JP decoder. Bug 563618, r=Masatoshi Kimura <VYV03354@nifty.ne.jp>
authorSimon Montagu <smontagu@smontagu.org>
Tue, 11 May 2010 17:38:25 +0300
changeset 42130 0841ec7eec87b7a462cd8fa7a44d33cebe0aae79
parent 42129 93874cf6d6ba752200d0b4821a720058aaa2ca86
child 42131 e3eea7c5ede17f79ac30cbf48cfda9b556924508
push idunknown
push userunknown
push dateunknown
reviewersMasatoshi
bugs563618
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Fix some errors with handling invalid sequences in the EUC-JP decoder. Bug 563618, r=Masatoshi Kimura <VYV03354@nifty.ne.jp>
intl/uconv/ucvja/nsJapaneseToUnicode.cpp
--- a/intl/uconv/ucvja/nsJapaneseToUnicode.cpp
+++ b/intl/uconv/ucvja/nsJapaneseToUnicode.cpp
@@ -339,20 +339,20 @@ NS_IMETHODIMP nsEUCJPToUnicodeV2::Conver
           case 1: // Index to table
           {
             PRUint8 off = sbIdx[*src];
             if(0xFF == off) {
               if (mErrBehavior == kOnError_Signal)
                 goto error_invalidchar;
               *dest++ = 0xFFFD;
                // if the first byte is valid for EUC-JP but the second 
-               // is not while being a valid US-ASCII(i.e. < 0xc0), save it
+               // is not while being a valid US-ASCII, save it
                // instead of eating it up !
-               if ( ! (*src & 0xc0)  )
-                 *dest++ = (PRUnichar) *src;;
+              if ( (PRUint8)*src < (PRUint8)0x7f )
+                --src;
             } else {
                *dest++ = gJapaneseMap[mData+off];
             }
             mState = 0;
             if(dest >= destEnd)
               goto error1;
           }
           break;
@@ -363,17 +363,17 @@ NS_IMETHODIMP nsEUCJPToUnicodeV2::Conver
               *dest++ = (0xFF61-0x00A1) + *src;
             } else {
               if (mErrBehavior == kOnError_Signal)
                 goto error_invalidchar;
               *dest++ = 0xFFFD;             
               // if 0x8e is not followed by a valid JIS X 0201 byte
               // but by a valid US-ASCII, save it instead of eating it up.
               if ( (PRUint8)*src < (PRUint8)0x7f )
-                 *dest++ = (PRUnichar) *src;
+                --src;
             }
             mState = 0;
             if(dest >= destEnd)
               goto error1;
           }
           break;
 
           case 3: // JIS 0212