From 949f1ae0b9cff9a042326bbf51c18806d7094ac0 Mon Sep 17 00:00:00 2001
From: MiMoHo <37556964+MiMoHo@users.noreply.github.com>
Date: Fri, 3 Jul 2026 20:58:57 +0200
Subject: [PATCH] fix: prevent crash when opening very large text files in the
editor
ReadTextActivity.checkIntent() read the whole file into memory before
setting it on the EditText. For file:// URIs it took the file.readText()
branch, which only caught Exception; a 100+ MB file threw
OutOfMemoryError (an Error, not an Exception), so it was uncaught and the
app crashed.
Guard checkIntent() with a 1 MB size check (mirroring Fossify Notes)
before reading. If the file exceeds the limit, show a 'File too large'
toast and finish the activity instead of loading it. Applies to both
file:// (File.length()) and content:// (getSizeFromContentUri) sources.
Fixes #123
---
CHANGELOG.md | 2 ++
.../filemanager/activities/ReadTextActivity.kt | 13 +++++++++++++
app/src/main/res/values/strings.xml | 1 +
3 files changed, 16 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd08943f9..c40d56f0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Fixed the modification of the original timestamp when decompressing folders ([#190])
+- Fixed a crash when opening very large text files in the built-in editor by adding a 1 MB size limit ([#123])
## [1.6.1] - 2026-02-14
### Changed
@@ -125,6 +126,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#105]: https://github.com/FossifyOrg/File-Manager/issues/105
[#106]: https://github.com/FossifyOrg/File-Manager/issues/106
[#120]: https://github.com/FossifyOrg/File-Manager/issues/120
+[#123]: https://github.com/FossifyOrg/File-Manager/issues/123
[#131]: https://github.com/FossifyOrg/File-Manager/issues/131
[#136]: https://github.com/FossifyOrg/File-Manager/issues/136
[#149]: https://github.com/FossifyOrg/File-Manager/issues/149
diff --git a/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt b/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt
index 9696e0650..0600f07b1 100644
--- a/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt
+++ b/app/src/main/kotlin/org/fossify/filemanager/activities/ReadTextActivity.kt
@@ -34,6 +34,7 @@ class ReadTextActivity : SimpleActivity() {
private const val SELECT_SAVE_FILE_INTENT = 1
private const val SELECT_SAVE_FILE_AND_EXIT_INTENT = 2
private const val KEY_UNSAVED_TEXT = "KEY_UNSAVED_TEXT"
+ private const val FILE_SIZE_LIMIT = 1000 * 1000 // 1 MB, same limit as Fossify Notes
}
private val binding by viewBinding(ActivityReadTextBinding::inflate)
@@ -285,6 +286,18 @@ class ReadTextActivity : SimpleActivity() {
}
private fun checkIntent(uri: Uri, savedInstanceState: Bundle?) {
+ val fileSize = if (uri.scheme == "file") {
+ File(uri.path!!).length()
+ } else {
+ getSizeFromContentUri(uri)
+ }
+
+ if (fileSize > FILE_SIZE_LIMIT) {
+ toast(R.string.file_too_large)
+ finish()
+ return
+ }
+
originalText = if (uri.scheme == "file") {
filePath = uri.path!!
val file = File(filePath)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 07a68b549..009fe67a5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -40,6 +40,7 @@
File Editor
+ File too large, the limit is 1MB
Storage analysis