Bug 961498: Prevent ICO decoder from exploding when faced with single-resource ICOs r=rnewman

This commit is contained in:
Chris Kitching 2014-01-19 19:25:47 +00:00
Родитель 5015c16747
Коммит b2dd2df186
3 изменённых файлов: 4 добавлений и 5 удалений

Просмотреть файл

@ -5,7 +5,6 @@
package org.mozilla.gecko.favicons.decoders; package org.mozilla.gecko.favicons.decoders;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.gfx.BitmapUtils; import org.mozilla.gecko.gfx.BitmapUtils;
import java.util.Iterator; import java.util.Iterator;
@ -87,7 +86,7 @@ public class FaviconDecoder {
result = new LoadFaviconResult(); result = new LoadFaviconResult();
result.mOffset = offset; result.mOffset = offset;
result.mLength = length; result.mLength = length;
result.mHasMultipleBitmaps = false; result.mIsICO = false;
// We assume here that decodeByteArray doesn't hold on to the entire supplied // 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. // buffer -- worst case, each of our buffers will be twice the necessary size.

Просмотреть файл

@ -345,7 +345,7 @@ public class ICODecoder implements Iterable<Bitmap> {
result.mFaviconBytes = mDecodand; result.mFaviconBytes = mDecodand;
result.mOffset = mOffset; result.mOffset = mOffset;
result.mLength = mLen; result.mLength = mLen;
result.mHasMultipleBitmaps = mIconDirectory.length > 1; result.mIsICO = true;
return result; return result;
} }

Просмотреть файл

@ -25,7 +25,7 @@ public class LoadFaviconResult {
int mOffset; int mOffset;
int mLength; int mLength;
boolean mHasMultipleBitmaps; boolean mIsICO;
Iterator<Bitmap> mBitmapsDecoded; Iterator<Bitmap> mBitmapsDecoded;
public Iterator<Bitmap> getBitmaps() { public Iterator<Bitmap> getBitmaps() {
@ -49,7 +49,7 @@ public class LoadFaviconResult {
// For results containing a single image, we re-encode the result as a PNG in an effort to // For results containing a single image, we re-encode the result as a PNG in an effort to
// save space. // save space.
if (!mHasMultipleBitmaps) { if (!mIsICO) {
Bitmap favicon = ((FaviconDecoder.SingleBitmapIterator) mBitmapsDecoded).peek(); Bitmap favicon = ((FaviconDecoder.SingleBitmapIterator) mBitmapsDecoded).peek();
byte[] data = null; byte[] data = null;
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();