Bug 1106347 - Don't die when retrieving over-large favicons from the database. r=mfinkle, a=lsblakk
authorRichard Newman <rnewman@mozilla.com>
Fri, 05 Dec 2014 16:54:47 -0800
changeset 234324 a0c7fb4511b3b9e277647ddb5f0c5aa4fe4e5dee
parent 234323 9ad491807c824c3e4aa705aefce4fe81652e25d7
child 234325 74a720385cb5cd3b2a881b008fb4ef5c97033566
push id4268
push userryanvm@gmail.com
push dateMon, 22 Dec 2014 22:22:50 +0000
treeherdermozilla-beta@e83d78f377b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, lsblakk
bugs1106347
milestone35.0
Bug 1106347 - Don't die when retrieving over-large favicons from the database. r=mfinkle, a=lsblakk
mobile/android/base/db/LocalBrowserDB.java
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -992,28 +992,46 @@ public class LocalBrowserDB {
      */
     public LoadFaviconResult getFaviconForUrl(ContentResolver cr, String faviconURL) {
         final Cursor c = cr.query(mFaviconsUriWithProfile,
                                   new String[] { Favicons.DATA },
                                   Favicons.URL + " = ? AND " + Favicons.DATA + " IS NOT NULL",
                                   new String[] { faviconURL },
                                   null);
 
+        boolean shouldDelete = false;
         byte[] b = null;
         try {
             if (!c.moveToFirst()) {
                 return null;
             }
 
             final int faviconIndex = c.getColumnIndexOrThrow(Favicons.DATA);
-            b = c.getBlob(faviconIndex);
+            try {
+                b = c.getBlob(faviconIndex);
+            } catch (IllegalStateException e) {
+                // This happens when the blob is more than 1MB: Bug 1106347.
+                // Delete that row.
+                shouldDelete = true;
+            }
         } finally {
             c.close();
         }
 
+        if (shouldDelete) {
+            try {
+                Log.d(LOGTAG, "Deleting invalid favicon.");
+                cr.delete(mFaviconsUriWithProfile,
+                          Favicons.URL + " = ?",
+                          new String[] { faviconURL });
+            } catch (Exception e) {
+                // Do nothing.
+            }
+        }
+
         if (b == null) {
             return null;
         }
 
         return FaviconDecoder.decodeFavicon(b);
     }
 
     /**