Cherry pick: [Android] Fix bug in address parser.

Bug: 12125045

Original description:

[Android] Fix bug in address parser.

Substring takes a length, not an index.

Bug:b/12125045

BUG=

Committed:
https://src.chromium.org/viewvc/chrome?view=rev&revision=253956

Change-Id: I2685a366f70b191c85e01522efcd6be319bf4da9
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewMiscTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewMiscTest.java
index 43c23cd..75ac4c5 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewMiscTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/ContentViewMiscTest.java
@@ -46,7 +46,8 @@
         assertNull(ContentViewStatics.findAddress("This is some random text"));
 
         String googleAddr = "1600 Amphitheatre Pkwy, Mountain View, CA 94043";
-        assertEquals(googleAddr, ContentViewStatics.findAddress(googleAddr));
+        String testString = "Address: " + googleAddr + "  in a string";
+        assertEquals(googleAddr, ContentViewStatics.findAddress(testString));
     }
 
     @SmallTest
diff --git a/content/common/android/address_parser.cc b/content/common/android/address_parser.cc
index 15874fd..5821a23 100644
--- a/content/common/android/address_parser.cc
+++ b/content/common/android/address_parser.cc
@@ -51,7 +51,8 @@
 bool FindAddress(const base::string16& text, base::string16* address) {
   size_t start, end;
   if (FindAddress(text.begin(), text.end(), &start, &end)) {
-    address->assign(text.substr(start, end));
+    size_t len = end >= start ? end - start : 0;
+    address->assign(text.substr(start, len));
     return true;
   }
   return false;