pdf: guard CropScreen bounds fallback against stream and size failures
- Commit
c884235bcceb47c865c006cd5f9bf13a15026511- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:11 UTC (28 days ago)
- Parents
003327c
When the full ImageDecoder decode fails, the bounds-only fallback ran unprotected: openInputStream throwing (revoked permission, vanished file) crashed the LaunchedEffect, and a null stream or undecodable bytes left outWidth/outHeight at 0, producing IntSize(0, 0) and a NaN photoRatio that crashed Modifier.size downstream. Catch stream failures and only publish originalSize for positive dimensions; the screen keeps its AsyncImage loading state while originalSize is null. Continue still completes with the default quadrilateral, and exporting an undecodable source already fails cleanly downstream (see savePdfToUriBadSourceFailsCleanly).
Diff
pdf/src/main/java/com/vayunmathur/pdf/ui/CropScreen.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/ui/CropScreen.kt b/pdf/src/main/java/com/vayunmathur/pdf/ui/CropScreen.ktindex 8988718d8d..60e0a5e2e1 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/ui/CropScreen.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/ui/CropScreen.kt@@ -94,11 +94,18 @@ fun CropScreen( } } else { withContext(Dispatchers.IO) {- val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }- context.contentResolver.openInputStream(uri)?.use {- BitmapFactory.decodeStream(it, null, options)+ runCatching {+ val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }+ context.contentResolver.openInputStream(uri)?.use {+ BitmapFactory.decodeStream(it, null, options)+ }+ // Zero dimensions mean the bounds decode failed (null stream or+ // undecodable data); leave originalSize null so the screen keeps+ // showing its loading state instead of dividing by zero below.+ if (options.outWidth > 0 && options.outHeight > 0) {+ originalSize = IntSize(options.outWidth, options.outHeight)+ } }- originalSize = IntSize(options.outWidth, options.outHeight) } } }