Check for (and clear) Exceptions thrown by TransferParameters
In GraphicsJNI::getColorSpace, which returns an
android.graphics.ColorSpace for a Bitmap, Skia reads the encoded
transfer function which then gets passed to the TransferParameters
constructor. It's possible for that constructor to throw an Exception,
in which case we cannot call JNI functions without handling the
Exception. Clear it and return null, since we are now unable to create
an android.graphics.ColorSpace.
Bug: 198155681
Test: I805aba8c078aac71d92ea71a199c2e1fe52df8fd
Flag: EXEMPT trivial bug fix
Change-Id: Ib1f7cbcc62a4722a2379b111838584cc4b6a36cc
diff --git a/libs/hwui/jni/Graphics.cpp b/libs/hwui/jni/Graphics.cpp
index 07e97f8..a88139d 100644
--- a/libs/hwui/jni/Graphics.cpp
+++ b/libs/hwui/jni/Graphics.cpp
@@ -583,6 +583,16 @@
transferParams.a, transferParams.b, transferParams.c, transferParams.d,
transferParams.e, transferParams.f, transferParams.g);
+ // Some transfer functions that are considered valid by Skia are not
+ // accepted by android.graphics.
+ if (hasException(env)) {
+ // Callers (e.g. Bitmap#getColorSpace) are not expected to throw an
+ // Exception, so clear it and return null, which is a documented
+ // possibility.
+ env->ExceptionClear();
+ return nullptr;
+ }
+
jfloatArray xyzArray = env->NewFloatArray(9);
jfloat xyz[9] = {
xyzMatrix.vals[0][0],