Fix quote crash when we decode an image of 0 length.

Fixes #7983
This commit is contained in:
Greyson Parrelli 2018-08-02 15:50:01 -04:00
parent 6db3f249c6
commit c5014f9471

View File

@ -71,11 +71,13 @@ public class BitmapUtil {
.downsample(DownsampleStrategy.AT_MOST)
.submit(maxImageWidth, maxImageHeight)
.get();
if (scaledBitmap == null) {
throw new BitmapDecodingException("Unable to decode image");
}
Log.i(TAG, "Initial scaled bitmap has size of " + scaledBitmap.getByteCount() + " bytes.");
try {
do {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -92,9 +94,15 @@ public class BitmapUtil {
quality = Math.max(nextQuality, MIN_COMPRESSION_QUALITY);
}
while (bytes.length > maxImageSize && attempts++ < MAX_COMPRESSION_ATTEMPTS);
if (bytes.length > maxImageSize) {
throw new BitmapDecodingException("Unable to scale image below: " + bytes.length);
}
if (bytes.length <= 0) {
throw new BitmapDecodingException("Decoding failed. Bitmap has a length of " + bytes.length + " bytes.");
}
Log.w(TAG, "createScaledBytes(" + model.toString() + ") -> quality " + Math.min(quality, MAX_COMPRESSION_QUALITY) + ", " + attempts + " attempt(s)");
return new ScaleResult(bytes, scaledBitmap.getWidth(), scaledBitmap.getHeight());
} finally {