volley: do not allow empty sizes to the bitmap constructor

fixes #357
refactor-toolbar
Floens 8 years ago
parent d9ee4f5afd
commit 17d3b62665
  1. 18
      Clover/app/src/main/java/com/android/volley/toolbox/ImageRequest.java

@ -16,6 +16,10 @@
package com.android.volley.toolbox;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
@ -23,10 +27,6 @@ import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyLog;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
/**
* A canned request for getting an image at a given URL and calling
* back with a decoded Bitmap.
@ -163,9 +163,15 @@ public class ImageRequest extends Request<Bitmap> {
Bitmap tempBitmap =
BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
// If necessary, scale down to the maximal acceptable size.
if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth ||
// Disallow dos by checking the size of the tempBitmap, otherwise the bitmap
// constructor will throw an IllegalArgumentException.
if (tempBitmap != null &&
(tempBitmap.getWidth() == 0 || tempBitmap.getHeight() == 0)) {
bitmap = null;
tempBitmap.recycle();
} else if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth ||
tempBitmap.getHeight() > desiredHeight)) {
// If necessary, scale down to the maximal acceptable size.
bitmap = Bitmap.createScaledBitmap(tempBitmap,
desiredWidth, desiredHeight, true);
tempBitmap.recycle();

Loading…
Cancel
Save