From f8dbee6597b0c9eefb1b38d7153a7a329601d520 Mon Sep 17 00:00:00 2001
From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com>
Date: Sun, 13 Apr 2025 22:12:08 -0700
Subject: [PATCH] fix(IconOptions): add maximum custom image size limit
Images that are too large cause issues when creating bitmaps, causing an OOM.
---
.../ui/screens/iconopts/IconOptionsModel.kt | 16 ++++++++++++++++
app/src/main/res/values/strings.xml | 3 ++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/iconopts/IconOptionsModel.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/iconopts/IconOptionsModel.kt
index 6b9803f..c7f72f2 100644
--- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/iconopts/IconOptionsModel.kt
+++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/iconopts/IconOptionsModel.kt
@@ -2,6 +2,7 @@ package com.aliucord.manager.ui.screens.iconopts
import android.app.Application
import android.net.Uri
+import android.provider.OpenableColumns
import android.util.Log
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
@@ -39,6 +40,21 @@ class IconOptionsModel(
fun changeSelectedImageUri(uri: Uri) = screenModelScope.launchBlock {
try {
+ // Check file size first
+ val query = application.contentResolver.query(uri, null, null, null, null)
+ ?: throw IOException("Failed to query selected image uri")
+
+ val size = query.use { cursor ->
+ cursor.moveToFirst()
+ cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE))
+ }
+
+ if (size > 1024 * 256) { // 256KiB
+ application.showToast(R.string.iconopts_failed_image_too_big)
+ return@launchBlock
+ }
+
+ // Read file bytes
val bytes = application.contentResolver
.openInputStream(uri)
?.use { it.readBytes() }
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d5a1d0b..1dae263 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -171,7 +171,7 @@
Does not alter the original icon, instead only adding the missing monochrome icon to the APK.
Changes the original icon color to Aliucord\'s branding.
Select a custom icon background color.
- Select a custom replacement image. Note that the image must have sufficient padding as per the Adaptive Icon foreground guidelines. Android 8+ only.
+ Select a custom replacement image. Note that the image must have sufficient padding as per the Adaptive Icon foreground guidelines. Android 8+ only. Maximum image size is 256KiB.
Hue & Saturation
The main HSV color components.
Lightness
@@ -179,6 +179,7 @@
Hex Color
Manually enter the RGB hex value of the color. Transparency is ignored!
Failed to open image
+ Image size exceeds maximum of 256KiB
Select Image
Example image
Preview