From 467361dbcf14ad0612b987e5e7aef1a4eb37145a Mon Sep 17 00:00:00 2001 From: Tom Taylor Date: Thu, 5 Oct 2017 11:27:21 -0700 Subject: [PATCH] 37742976 - Catch bad gifs * A security researcher crafted a gif that would cause the Android Bitmap code to throw an NPE. That would cause messaging to crash when decoding the NPE. The frameworks team is changing the underlying code to throw an OutOfMemoryError instead of a NullPointerException. In order to catch both errors, the code needs to catch Throwable. Test: I added code to GifImageResource.getDrawable to throw a new OutOfMemoryError and then used the debugger to verify it was caught by the new catch Throwable statement. I did the same test with NullPointerException. I tested attaching gif images and sending them to verify the gif path still worked. BUG=37742976 Change-Id: If71a7e65f8c0b083fe6c4b79f78358666338d59d --- .../messaging/datamodel/media/GifImageResource.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/android/messaging/datamodel/media/GifImageResource.java b/src/com/android/messaging/datamodel/media/GifImageResource.java index 6801165..cbea1ee 100644 --- a/src/com/android/messaging/datamodel/media/GifImageResource.java +++ b/src/com/android/messaging/datamodel/media/GifImageResource.java @@ -58,10 +58,10 @@ public class GifImageResource extends ImageResource { public Drawable getDrawable(Resources resources) { try { return new FrameSequenceDrawable(mFrameSequence); - } catch (final Exception e) { - // Malicious gif images can make platform throw different kind of exceptions. Catch - // them all. - LogUtil.e(LogUtil.BUGLE_TAG, "Error getting drawable for GIF", e); + } catch (final Throwable t) { + // Malicious gif images can make the platform throw different kind of throwables, such + // as OutOfMemoryError and NullPointerException. Catch them all. + LogUtil.e(LogUtil.BUGLE_TAG, "Error getting drawable for GIF", t); return null; } }