From 3aa18fa9ac956d7dd3941be47ff231ca916b5d0c Mon Sep 17 00:00:00 2001 From: k1ngsterr1 Date: Fri, 20 Feb 2026 05:46:39 +0500 Subject: [PATCH] fix: Improve error handling for image bounds decoding in MediaUtils --- .../java/com/rosetta/messenger/utils/MediaUtils.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt b/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt index 402c675..fc36f51 100644 --- a/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt +++ b/app/src/main/java/com/rosetta/messenger/utils/MediaUtils.kt @@ -51,9 +51,15 @@ object MediaUtils { val boundsOptions = BitmapFactory.Options().apply { inJustDecodeBounds = true } - context.contentResolver.openInputStream(uri)?.use { inputStream -> + val boundsStream = context.contentResolver.openInputStream(uri) + if (boundsStream == null) { + logImage("bounds stream open failed") + return@withContext null + } + boundsStream.use { inputStream -> + // decodeStream returns null when inJustDecodeBounds=true; we only need outWidth/outHeight. BitmapFactory.decodeStream(inputStream, null, boundsOptions) - } ?: return@withContext null + } if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) { logImage("bounds decode failed, trying direct decode fallback")