From beebd3ca9bd3289f2bf76e0cd0814e34505d5ab6 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 6 Dec 2019 12:45:11 -0500 Subject: ImageDecoder: Disallow empty/unsorted crop rects Bug: 135133301 Test: Idf64474f28c0bf3f77616a31d843d84fbfd570ab If the specified crop Rect is empty or unsorted, throw an IllegalStateException, like we do if the Rect does not fit in the target size. This is a change in behavior to make it more consistent. Here are the specific behavior changes: - an empty crop rect was previously supported in all cases, but would result in a zero width and/or height Bitmap/Drawable. If one dimension is non-zero, it still affects layout, though nothing is drawn. This is not useful, so the new Exception is more helpful. (It is also more consistent with setTargetSize, which throws an IllegalArgumentException for non-positive dimensions.) - a negative width or height in decodeBitmap, or on a static image in decodeDrawable, previously threw an IOException when trying to call SkBitmap::setInfo with a negative width or height. Throwing an IllegalStateException is more consistent with other invalid crop rects - a negative width or height in decodeDrawable on an animated image previously resulted in an AnimatedImageDrawable with a negative intrinsic width and/or height. When passed to an ImageView, this dimension ends up being 1. Again, this does not seem useful. Change-Id: I15d2f77125799413eaf55d417e98ff34599e2eb4 --- graphics/java/android/graphics/ImageDecoder.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java index 6619dba159c2..8ebac667aca3 100644 --- a/graphics/java/android/graphics/ImageDecoder.java +++ b/graphics/java/android/graphics/ImageDecoder.java @@ -1675,6 +1675,9 @@ public final class ImageDecoder implements AutoCloseable { if (r == null) { return; } + if (r.width() <= 0 || r.height() <= 0) { + throw new IllegalStateException("Subset " + r + " is empty/unsorted"); + } if (r.left < 0 || r.top < 0 || r.right > width || r.bottom > height) { throw new IllegalStateException("Subset " + r + " not contained by " + "scaled image bounds: (" + width + " x " + height + ")"); -- cgit v1.2.3-59-g8ed1b