fix: Improve error handling for image bounds decoding in MediaUtils

This commit is contained in:
2026-02-20 05:46:39 +05:00
parent b6f266faa4
commit 3aa18fa9ac

View File

@@ -51,9 +51,15 @@ object MediaUtils {
val boundsOptions = val boundsOptions =
BitmapFactory.Options().apply { inJustDecodeBounds = true } 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) BitmapFactory.decodeStream(inputStream, null, boundsOptions)
} ?: return@withContext null }
if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) { if (boundsOptions.outWidth <= 0 || boundsOptions.outHeight <= 0) {
logImage("bounds decode failed, trying direct decode fallback") logImage("bounds decode failed, trying direct decode fallback")