Bug 961498: Prevent ICO decoder from exploding when faced with single-resource ICOs r=rnewman
authorChris Kitching <chriskitching@linux.com>
Sun, 19 Jan 2014 19:25:47 +0000
changeset 164258 b56b70d548a215dadd3b2bd854225713deea10d5
parent 164241 87bf998d0f3a3a0313983afc568d597fadd926d6
child 164259 57317659a609c199207c86c0415a554203586554
push id38658
push userMs2ger@gmail.com
push dateMon, 20 Jan 2014 08:36:21 +0000
treeherdermozilla-inbound@d86d7bf553c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs961498
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 961498: Prevent ICO decoder from exploding when faced with single-resource ICOs r=rnewman
mobile/android/base/favicons/decoders/FaviconDecoder.java
mobile/android/base/favicons/decoders/ICODecoder.java
mobile/android/base/favicons/decoders/LoadFaviconResult.java
--- a/mobile/android/base/favicons/decoders/FaviconDecoder.java
+++ b/mobile/android/base/favicons/decoders/FaviconDecoder.java
@@ -1,16 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.favicons.decoders;
 
 import android.graphics.Bitmap;
-import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.gfx.BitmapUtils;
 
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
 /**
  * Class providing static utility methods for decoding favicons.
  */
@@ -82,17 +81,17 @@ public class FaviconDecoder {
      *         decoded.
      */
     public static LoadFaviconResult decodeFavicon(byte[] buffer, int offset, int length) {
         LoadFaviconResult result;
         if (isDecodableByAndroid(buffer, offset)) {
             result = new LoadFaviconResult();
             result.mOffset = offset;
             result.mLength = length;
-            result.mHasMultipleBitmaps = false;
+            result.mIsICO = false;
 
             // We assume here that decodeByteArray doesn't hold on to the entire supplied
             // buffer -- worst case, each of our buffers will be twice the necessary size.
             result.mBitmapsDecoded = new SingleBitmapIterator(BitmapUtils.decodeByteArray(buffer, offset, length));
             result.mFaviconBytes = buffer;
 
             return result;
         }
--- a/mobile/android/base/favicons/decoders/ICODecoder.java
+++ b/mobile/android/base/favicons/decoders/ICODecoder.java
@@ -340,17 +340,17 @@ public class ICODecoder implements Itera
         }
 
         LoadFaviconResult result = new LoadFaviconResult();
 
         result.mBitmapsDecoded = bitmaps;
         result.mFaviconBytes = mDecodand;
         result.mOffset = mOffset;
         result.mLength = mLen;
-        result.mHasMultipleBitmaps = mIconDirectory.length > 1;
+        result.mIsICO = true;
 
         return result;
     }
 
     /**
      * Inner class to iterate over the elements in the ICO represented by the enclosing instance.
      */
     private class ICOIterator implements Iterator<Bitmap> {
--- a/mobile/android/base/favicons/decoders/LoadFaviconResult.java
+++ b/mobile/android/base/favicons/decoders/LoadFaviconResult.java
@@ -20,17 +20,17 @@ import java.util.Iterator;
  */
 public class LoadFaviconResult {
     private static final String LOGTAG = "LoadFaviconResult";
 
     byte[] mFaviconBytes;
     int mOffset;
     int mLength;
 
-    boolean mHasMultipleBitmaps;
+    boolean mIsICO;
     Iterator<Bitmap> mBitmapsDecoded;
 
     public Iterator<Bitmap> getBitmaps() {
         return mBitmapsDecoded;
     }
 
     /**
      * Return a representation of this result suitable for storing in the database.
@@ -44,17 +44,17 @@ public class LoadFaviconResult {
             final byte[] normalised = new byte[mLength];
             System.arraycopy(mFaviconBytes, mOffset, normalised, 0, mLength);
             mOffset = 0;
             mFaviconBytes = normalised;
         }
 
         // For results containing a single image, we re-encode the result as a PNG in an effort to
         // save space.
-        if (!mHasMultipleBitmaps) {
+        if (!mIsICO) {
             Bitmap favicon = ((FaviconDecoder.SingleBitmapIterator) mBitmapsDecoded).peek();
             byte[] data = null;
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
 
             if (favicon.compress(Bitmap.CompressFormat.PNG, 100, stream)) {
                 data = stream.toByteArray();
             } else {
                 Log.w(LOGTAG, "Favicon compression failed.");