Add check for stride when calling bulk ShadowBitmap.getPixels

Robolectric was allowing invalid calls to Bitmap.getPixels that would cause an
ArrayOutOfBoundsException in Android. This would happen if the 'stride' value
exceeded the width.

Add a ctesque regression test as well.

PiperOrigin-RevId: 362974483
diff --git a/integration_tests/ctesque/src/test/java/android/graphics/BitmapTest.java b/integration_tests/ctesque/src/test/java/android/graphics/BitmapTest.java
index 34cb5e9..afc04fc 100644
--- a/integration_tests/ctesque/src/test/java/android/graphics/BitmapTest.java
+++ b/integration_tests/ctesque/src/test/java/android/graphics/BitmapTest.java
@@ -255,4 +255,16 @@
 
     assertThat(exception).hasMessageThat().contains("width and height must be > 0");
   }
+
+  @Test
+  public void getBitmapPixels_strideTooLong() {
+    int[] bitmapPixels = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+    Bitmap bitmap = Bitmap.createBitmap(bitmapPixels, 3, 3, Bitmap.Config.ARGB_8888);
+    int[] pixelsCopy = new int[bitmap.getHeight() * bitmap.getWidth()];
+    assertThrows(
+        ArrayIndexOutOfBoundsException.class,
+        () ->
+            bitmap.getPixels(
+                pixelsCopy, 0, bitmap.getRowBytes(), 0, 0, bitmap.getWidth(), bitmap.getHeight()));
+  }
 }
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmap.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmap.java
index c09574d..0f03bc4 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmap.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowBitmap.java
@@ -412,11 +412,12 @@
   @Implementation
   protected void getPixels(
       int[] pixels, int offset, int stride, int x, int y, int width, int height) {
-    if (x != 0 ||
-        y != 0 ||
-        width != getWidth() ||
-        height != getHeight() ||
-        pixels.length != colors.length) {
+    if (x != 0
+        || y != 0
+        || width != getWidth()
+        || height != getHeight()
+        || stride != getWidth()
+        || pixels.length != colors.length) {
       for (int y0 = 0; y0 < height; y0++) {
         for (int x0 = 0; x0 < width; x0++) {
           pixels[offset + y0 * stride + x0] = colors[(y0 + y) * getWidth() + x0 + x];