Apply a local patch to ucol.cpp


BUG=433866
TEST=See the bug.
R=mbarbella@google.com

Review URL: https://codereview.chromium.org/751333003

git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/icu52@293126 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/README.chromium b/README.chromium
index f6015a4..bbb7f8d 100644
--- a/README.chromium
+++ b/README.chromium
@@ -245,3 +245,9 @@
                      http://bugs.icu-project.org/trac/ticket/11370
                      http://bugs.icu-project.org/trac/ticket/11371
 
+13. Apply the patch for collator
+   - patches/col.patch
+   - No upstream bug filed because the upstream code was completely
+     rewritten during the ICU 53 cycle.
+
+
diff --git a/patches/col.patch b/patches/col.patch
new file mode 100644
index 0000000..aa117fe
--- /dev/null
+++ b/patches/col.patch
@@ -0,0 +1,29 @@
+Index: source/i18n/ucol.cpp
+===================================================================
+--- source/i18n/ucol.cpp	(revision 292709)
++++ source/i18n/ucol.cpp	(working copy)
+@@ -2259,6 +2259,9 @@
+         if (data->pos + 1 == data->endp) {
+             return *(data->pos ++);
+         }
++        if (data->pos >= data->endp) {
++            return (UChar) -1; // return U+FFFF (non-char) to indicate an error
++        }
+     }
+     else {
+         if (innormbuf) {
+@@ -2821,7 +2824,13 @@
+                                 }
+                             }
+                         } else if (U16_IS_LEAD(schar)) {
+-                            miss = U16_GET_SUPPLEMENTARY(schar, getNextNormalizedChar(source));
++                            UChar nextChar = getNextNormalizedChar(source);
++                            const UChar* prevPos = source->pos;
++                            if (U16_IS_TRAIL(nextChar)) {
++                                miss = U16_GET_SUPPLEMENTARY(schar, nextChar);
++                            } else if (prevPos < source->pos) {
++                                goBackOne(source);
++                            }
+                         }
+ 
+                         uint8_t sCC;
diff --git a/source/i18n/ucol.cpp b/source/i18n/ucol.cpp
index b0d819f..e5ff44e 100644
--- a/source/i18n/ucol.cpp
+++ b/source/i18n/ucol.cpp
@@ -2259,6 +2259,9 @@
         if (data->pos + 1 == data->endp) {
             return *(data->pos ++);
         }
+        if (data->pos >= data->endp) {
+            return (UChar) -1; // return U+FFFF (non-char) to indicate an error
+        }
     }
     else {
         if (innormbuf) {
@@ -2821,7 +2824,13 @@
                                 }
                             }
                         } else if (U16_IS_LEAD(schar)) {
-                            miss = U16_GET_SUPPLEMENTARY(schar, getNextNormalizedChar(source));
+                            UChar nextChar = getNextNormalizedChar(source);
+                            const UChar* prevPos = source->pos;
+                            if (U16_IS_TRAIL(nextChar)) {
+                                miss = U16_GET_SUPPLEMENTARY(schar, nextChar);
+                            } else if (prevPos < source->pos) {
+                                goBackOne(source);
+                            }
                         }
 
                         uint8_t sCC;