nativeGetAllocationByteCount should return a positive int
Make sure Bitmap_Delegate.nativeGetAllocationByteCount always returns a
positive integer by returning Integer.MAX_VALUE if the the size of the
picture overflows the int. That is to prevent an exception coming from
passing a negative value to NativeAllocationRegistry.
The result is only passed to NativeAllocationRegistry that registers at
most Integer.MAX_VALUE, so that has no impact in layoutlib.
Test: layoutlib tests
Change-Id: I1e637a92df161c341a6ba07cbbe98bac6ec96fcd
diff --git a/bridge/src/android/graphics/Bitmap_Delegate.java b/bridge/src/android/graphics/Bitmap_Delegate.java
index 0064537..6c72cb2 100644
--- a/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -608,7 +608,8 @@
if (delegate == null) {
return 0;
}
- return nativeRowBytes(nativeBitmap) * delegate.mImage.getHeight();
+ int size = nativeRowBytes(nativeBitmap) * delegate.mImage.getHeight();
+ return size < 0 ? Integer.MAX_VALUE : size;
}