From 352f0b560d463d5fa674a836a22c843208184cf1 Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:43:26 +0100 Subject: [PATCH 1/2] fix(android): reject instead of crashing when bitmap decoding fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both crop paths signalled an unusable source with `?: throw Error(...)`. `kotlin.Error` maps to `java.lang.Error`, which is not an `Exception`, so the throw slipped past the only guard around the crop work (`catch (e: Exception)`) and escaped `moduleCoroutineScope.launch { }` — a bare `CoroutineScope(Dispatchers.Default)` with no CoroutineExceptionHandler. It reached the thread's uncaught handler, so the app crashed and the promise never settled. `BitmapRegionDecoder.newInstance` returns null for anything it can't decode, so this is easy to hit: a non-image URL (`cropImage(url)` on a PDF, or a server returning an HTML error page with HTTP 200), or a GIF/HEIC/corrupt file. iOS and web reject for the same input. `OutOfMemoryError` while decoding large images escaped the same way. Throw `JSApplicationIllegalArgumentException`, which the JS layer already surfaces as a normal rejection, and widen the guard to `Throwable` so errors become rejections too. --- .../imageeditor/ImageEditorModuleImpl.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt index 53a92f3..3ff0077 100644 --- a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt +++ b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt @@ -186,7 +186,10 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { copyExif(reactContext, Uri.parse(uri), tempFile) } promise.resolve(getResultMap(tempFile, cropped, mimeType, includeBase64)) - } catch (e: Exception) { + } catch (e: Throwable) { + // Errors (e.g. OutOfMemoryError while decoding) must be turned into a rejection + // too: they don't extend Exception and would otherwise escape the coroutine and + // crash the app, leaving the promise unsettled. promise.reject(e) } } @@ -219,7 +222,9 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { BitmapRegionDecoder.newInstance(it) } else { @Suppress("DEPRECATION") BitmapRegionDecoder.newInstance(it, false) - } ?: throw Error("Could not create bitmap decoder. Uri: $uri") + } ?: throw JSApplicationIllegalArgumentException( + "Could not create bitmap decoder. Uri: $uri" + ) val imageHeight: Int = decoder.height val imageWidth: Int = decoder.width @@ -283,7 +288,9 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { BitmapRegionDecoder.newInstance(it) } else { @Suppress("DEPRECATION") BitmapRegionDecoder.newInstance(it, false) - } ?: throw Error("Could not create bitmap decoder. Uri: $uri") + } ?: throw JSApplicationIllegalArgumentException( + "Could not create bitmap decoder. Uri: $uri" + ) val orientation = getOrientation(reactContext, Uri.parse(uri)) val (x, y) = From 184aab093d0d34d490a337520b0624283b7108e0 Mon Sep 17 00:00:00 2001 From: D N <4661784+retyui@users.noreply.github.com> Date: Thu, 3 Dec 2026 10:34:38 +0100 Subject: [PATCH 2/2] style(android): apply spotless formatting --- .../imageeditor/ImageEditorModuleImpl.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt index 3ff0077..f94bc65 100644 --- a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt +++ b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt @@ -222,9 +222,10 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { BitmapRegionDecoder.newInstance(it) } else { @Suppress("DEPRECATION") BitmapRegionDecoder.newInstance(it, false) - } ?: throw JSApplicationIllegalArgumentException( - "Could not create bitmap decoder. Uri: $uri" - ) + } + ?: throw JSApplicationIllegalArgumentException( + "Could not create bitmap decoder. Uri: $uri" + ) val imageHeight: Int = decoder.height val imageWidth: Int = decoder.width @@ -288,9 +289,10 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { BitmapRegionDecoder.newInstance(it) } else { @Suppress("DEPRECATION") BitmapRegionDecoder.newInstance(it, false) - } ?: throw JSApplicationIllegalArgumentException( - "Could not create bitmap decoder. Uri: $uri" - ) + } + ?: throw JSApplicationIllegalArgumentException( + "Could not create bitmap decoder. Uri: $uri" + ) val orientation = getOrientation(reactContext, Uri.parse(uri)) val (x, y) =