Bug 867058 - Check bytes.length before decoding favicons. r=mfinkle, a=lsblakk
authorBrian Nicholson <bnicholson@mozilla.com>
Thu, 23 May 2013 11:42:30 -0700
changeset 142747 d13ef195810ba4a20ff38880bec823759286724a
parent 142746 c56382a7d4a68a9800972c887fe3c5a344f6a938
child 142748 ef997bd071b7cd26560168ae9e34711d6f0faf96
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, lsblakk
bugs867058
milestone23.0a2
Bug 867058 - Check bytes.length before decoding favicons. r=mfinkle, a=lsblakk
mobile/android/base/AwesomeBar.java
mobile/android/base/awesomebar/AllPagesTab.java
mobile/android/base/awesomebar/BookmarksTab.java
mobile/android/base/awesomebar/HistoryTab.java
mobile/android/base/db/LocalBrowserDB.java
mobile/android/base/widget/TopSitesView.java
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -727,17 +727,17 @@ public class AwesomeBar extends GeckoAct
             }
             case R.id.add_to_launcher: {
                 if (url == null) {
                     Log.e(LOGTAG, "Can't add to home screen because URL is null");
                     break;
                 }
 
                 Bitmap bitmap = null;
-                if (b != null) {
+                if (b != null && b.length > 0) {
                     bitmap = BitmapUtils.decodeByteArray(b);
                 }
 
                 String shortcutTitle = TextUtils.isEmpty(title) ? url.replaceAll("^([a-z]+://)?(www\\.)?", "") : title;
                 GeckoAppShell.createShortcut(shortcutTitle, url, bitmap, "");
                 break;
             }
             case R.id.share: {
--- a/mobile/android/base/awesomebar/AllPagesTab.java
+++ b/mobile/android/base/awesomebar/AllPagesTab.java
@@ -869,17 +869,17 @@ public class AllPagesTab extends Awesome
     public void storeFaviconsInMemCache(Cursor c) {
         try {
             if (c == null || !c.moveToFirst())
                 return;
 
             do {
                 final String url = c.getString(c.getColumnIndexOrThrow(Combined.URL));
                 final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Combined.FAVICON));
-                if (b == null)
+                if (b == null || b.length == 0)
                     continue;
 
                 Bitmap favicon = BitmapUtils.decodeByteArray(b);
                 if (favicon == null)
                     continue;
 
                 favicon = Favicons.getInstance().scaleImage(favicon);
                 Favicons.getInstance().putFaviconInMemCache(url, favicon);
--- a/mobile/android/base/awesomebar/BookmarksTab.java
+++ b/mobile/android/base/awesomebar/BookmarksTab.java
@@ -338,17 +338,17 @@ public class BookmarksTab extends Awesom
                 throw new IllegalStateException("Couldn't move cursor to position " + position);
 
             if (viewType == VIEW_TYPE_ITEM) {
                 updateTitle(viewHolder.titleView, cursor);
                 updateUrl(viewHolder, cursor);
 
                 byte[] b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
                 Bitmap favicon = null;
-                if (b != null) {
+                if (b != null && b.length > 0) {
                     Bitmap bitmap = BitmapUtils.decodeByteArray(b);
                     if (bitmap != null) {
                         favicon = Favicons.getInstance().scaleImage(bitmap);
                     }
                 }
                 String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
                 updateFavicon(viewHolder.faviconView, favicon, url);
             } else {
--- a/mobile/android/base/awesomebar/HistoryTab.java
+++ b/mobile/android/base/awesomebar/HistoryTab.java
@@ -186,17 +186,17 @@ public class HistoryTab extends AwesomeB
             String url = (String) historyItem.get(URLColumns.URL);
 
             updateTitle(viewHolder.titleView, title, url);
             updateUrl(viewHolder, url);
 
             byte[] b = (byte[]) historyItem.get(URLColumns.FAVICON);
             Bitmap favicon = null;
 
-            if (b != null) {
+            if (b != null && b.length > 0) {
                 Bitmap bitmap = BitmapUtils.decodeByteArray(b);
                 if (bitmap != null) {
                     favicon = Favicons.getInstance().scaleImage(bitmap);
                 }
             }
             updateFavicon(viewHolder.faviconView, favicon, url);
 
             Integer bookmarkId = (Integer) historyItem.get(Combined.BOOKMARK_ID);
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -706,17 +706,17 @@ public class LocalBrowserDB implements B
             c.close();
             return null;
         }
 
         int faviconIndex = c.getColumnIndexOrThrow(Combined.FAVICON);
         byte[] b = c.getBlob(faviconIndex);
         c.close();
 
-        if (b == null)
+        if (b == null || b.length == 0)
             return null;
 
         return BitmapUtils.decodeByteArray(b);
     }
 
     @Override
     public String getFaviconUrlForHistoryUrl(ContentResolver cr, String uri) {
         Cursor c = cr.query(mHistoryUriWithProfile,
--- a/mobile/android/base/widget/TopSitesView.java
+++ b/mobile/android/base/widget/TopSitesView.java
@@ -656,17 +656,17 @@ public class TopSitesView extends GridVi
 
                         Cursor c = BrowserDB.getThumbnailsForUrls(resolver, urls);
                         if (c == null || !c.moveToFirst()) {
                             return null;
                         }
 
                         final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Thumbnails.DATA));
                         Bitmap bitmap = null;
-                        if (b != null) {
+                        if (b != null && b.length > 0) {
                             bitmap = BitmapUtils.decodeByteArray(b);
                         }
                         c.close();
 
                         return bitmap;
                     }
 
                     @Override