Merge pull request #58 from barrydeen/fix/blurhash-zero-dim-crash

Fix crash on zero/negative blurhash dimensions
This commit is contained in:
Barry Deen
2026-07-23 11:00:58 -04:00
committed by GitHub
4 changed files with 6 additions and 4 deletions
+2 -2
View File
@@ -26,8 +26,8 @@ android {
applicationId = baseApplicationId
minSdk = 26
targetSdk = 35
versionCode = 3
versionName = "1.2.0"
versionCode = 4
versionName = "1.2.1"
resValue("string", "app_name", "Dark Wisp")
ndk {
@@ -3000,8 +3000,8 @@ internal fun rememberMediaPlaceholderPainter(
return@produceState
}
val dims = dimension?.split('x')
val width = dims?.getOrNull(0)?.toIntOrNull()?.coerceAtMost(100) ?: 32
val height = dims?.getOrNull(1)?.toIntOrNull()?.coerceAtMost(100) ?: 32
val width = dims?.getOrNull(0)?.toIntOrNull()?.takeIf { it > 0 }?.coerceAtMost(100) ?: 32
val height = dims?.getOrNull(1)?.toIntOrNull()?.takeIf { it > 0 }?.coerceAtMost(100) ?: 32
value = withContext(Dispatchers.Default) {
MediaHashDecoder.decode(thumbhash, blurhash, width, height)
?.asImageBitmap()
@@ -10,6 +10,7 @@ object BlurHashDecoder {
fun decode(blurHash: String?, width: Int, height: Int, punch: Float = 1f): Bitmap? {
if (blurHash == null || blurHash.length < 6) return null
if (width <= 0 || height <= 0) return null
val numComponents = decode83(blurHash, 0, 1)
val nx = (numComponents % 9) + 1
@@ -7,6 +7,7 @@ import com.madebyevan.thumbhash.ThumbHash
object MediaHashDecoder {
fun decode(thumbHash: String?, blurHash: String?, width: Int, height: Int): Bitmap? {
if (width <= 0 || height <= 0) return null
decodeThumbHash(thumbHash, width, height)?.let { return it }
return BlurHashDecoder.decode(blurHash, width, height)
}