Skip to content

fix: guard the text editor against opening very large files (OOM)#457

Open
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-123
Open

fix: guard the text editor against opening very large files (OOM)#457
MiMoHo wants to merge 1 commit into
FossifyOrg:mainfrom
MiMoHo:fix/issue-123

Conversation

@MiMoHo

@MiMoHo MiMoHo commented Jul 3, 2026

Copy link
Copy Markdown

Type of change(s)

  • Bug fix

What changed and why

Opening a large text file from the file list crashed the app. ReadTextActivity.checkIntent() reads the entire file into memory before setting it on the EditText. When a file is opened from the File-Manager list, commons openPathIntent adds the REAL_FILE_PATH extra, so the activity builds a file:// Uri and takes the file.readText() branch. That branch only catches Exception, but reading a 100+ MB file throws java.lang.OutOfMemoryError (an Error, not an Exception), so it goes uncaught and the app crashes. (The content:// branch already catches OutOfMemoryError, so the behaviour was inconsistent.) Even if the read succeeded, setText() of such large text on the UI thread would OOM/ANR.

This adds a 1 MB size guard at the start of checkIntent() — the same limit used by Fossify Notes — checked before any read. If the file exceeds the limit, a "File too large, the limit is 1MB" toast is shown and the activity finishes instead of loading the file. The check covers both file:// (via File.length()) and content:// (via getSizeFromContentUri) sources. As requested by @Aga-C on the issue, the message string mirrors Fossify Notes.

Changes:

  • ReadTextActivity.kt: add FILE_SIZE_LIMIT = 1000 * 1000 constant and a size check in checkIntent().
  • strings.xml: add file_too_large string.
  • CHANGELOG.md: note the fix under Unreleased / Fixed and add the [#123] link reference.

No new imports were needed: File is already imported and getSizeFromContentUri, toast and finish are available via the existing org.fossify.commons.extensions.* import.

Tests performed

Built fossDebug, installed on an Android 15 (API 35) emulator.

  • Opened a 5 MB text file via the built-in editor (ReadTextActivity): the activity now finishes immediately with a "File too large" toast and no OutOfMemory/crash (logcat clean). Before the fix this OOM-crashed.
  • A small text file still opens normally and shows its content in the editor.
  • detekt, lint, unit tests and build all pass locally (CI-equivalent).

Closes the following issue(s)

Checklist

  • I read the contribution guidelines.
  • I manually tested my changes on device/emulator.
  • I updated the "Unreleased" section in CHANGELOG.md (if applicable).
  • I have self-reviewed my pull request (no typos, formatting errors, etc.).
  • I understand every change in this pull request.

Coded with Opus 4.8 ultracode.

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 FossifyOrg#123
@MiMoHo MiMoHo requested a review from naveensingh as a code owner July 3, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File Editor: Open .txt crash

1 participant