Skip to content

[BUG] Crash when big txt file is previewed #4915

Open

Description

@jesmrec

Could be related with #3794

Steps to reproduce

  1. Create a big txt file (~30MB)
  2. In app, open it

Actual behaviour

Spinner of waiting... and finally a crash. Stacktrace:

Process: com.owncloud.android.debug, PID: 16420
                 java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 2240160 free bytes and 2187KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
                 	at android.text.MeasuredParagraph.<init>(MeasuredParagraph.java:129)
                 	at android.text.MeasuredParagraph.obtain(MeasuredParagraph.java:80)
                 	at android.text.MeasuredParagraph.buildForStaticLayoutInternal(MeasuredParagraph.java:596)
                 	at android.text.MeasuredParagraph.buildForStaticLayout(MeasuredParagraph.java:543)
                 	at android.text.PrecomputedText.createMeasuredParagraphs(PrecomputedText.java:526)
                 	at android.text.StaticLayout.generate(StaticLayout.java:886)
                 	at android.text.StaticLayout.<init>(StaticLayout.java:733)
                 	at android.text.StaticLayout.<init>(StaticLayout.java:0)
                 	at android.text.StaticLayout$Builder.build(StaticLayout.java:547)
                 	at android.widget.TextView.makeSingleLayout(TextView.java:11216)
                 	at android.widget.TextView.makeNewLayout(TextView.java:10992)
                 	at android.widget.TextView.onMeasure(TextView.java:11442)
                 	at androidx.appcompat.widget.AppCompatTextView.onMeasure(AppCompatTextView.java:615)
                 	at android.view.View.measure(View.java:29423)
                 	at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1533)
                 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                 	at android.widget.ScrollView.onMeasure(ScrollView.java:474)
                 	at android.view.View.measure(View.java:29423)
                 	at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:735)
                 	at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:481)
                 	at android.view.View.measure(View.java:29423)
                 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7068)
                 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                 	at android.view.View.measure(View.java:29423)
                 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7068)
                 	at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:760)
                 	at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:833)
                 	at android.view.View.measure(View.java:29423)
                 	at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:811)
                 	at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:632)
                 	at androidx.constraintlayout.core.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:452)
                 	at androidx.constraintlayout.core.widgets.analyzer.Direct.solveVerticalMatchConstraint(Direct.java:750)
                 	at androidx.constraintlayout.core.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:503)
                 	at androidx.constraintlayout.core.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:542)
                 	at androidx.constraintlayout.core.widgets.analyzer.Direct.solvingPass(Direct.java:224)
                 	at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.layout(ConstraintWidgetContainer.java:693)
                 	at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.solveLinearSystem(BasicMeasure.java:160)
                 	at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.solverMeasure(BasicMeasure.java:291)
                 	at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:120)
                 	at androidx.constraintlayout.widget.ConstraintLayout.resolveSystem(ConstraintLayout.java:1594)
                 	at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1708)
                 	at android.view.View.measure(View.java:29423)
                 	at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1156)
                 	at android.view.View.measure(View.java:29423)
                 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7068)
                 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                 	at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
                 	at android.view.View.measure(View.java:29423)
                 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7068)
09:48:23.297  I  Process is going to kill itself!
                 java.lang.Exception
                 	at android.os.Process.killProcess(Process.java:1495)
                 	at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:193)
                 	at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1098)
                 	at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1093)
                 	at java.lang.Thread.dispatchUncaughtException(Thread.java:3387)

Expected behaviour

File correctly opened

Reproducible with any Android version and backend.

Activity

  1. added this to the Backlog milestone on Jul 3, 2026
  2. DeepDiver1975 commented on Jul 6, 2026

    @DeepDiver1975
    Contributor

    Confirmed on current master. Root cause: the text preview loads the entire file into memory and hands the whole string to a single TextView, with no size cap — a ~30MB txt OOMs while StaticLayout/TextView.onMeasure builds the layout (matches your trace).

    Code path (owncloudApp/.../ui/preview/PreviewTextFragment.kt, master):

    • TextLoadAsyncTask.doInBackground reads the full file into a StringWriter line-by-line — L290, L306-310.
    • onPostExecute materializes it as one String — val text = String(result.buffer) L334.
    • showPreviewText sets it all at once — textView.text = text L384.
    • canBePreviewed (L426) gates only on mime type, never file size.

    Fix direction:

    • Cap what the preview loads/renders (read only the first N bytes/lines, or truncate the displayed string) and/or gate canBePreviewed/the load on a max size.
    • Prefer a paginated/streamed view or a scroll-bounded RecyclerView over a single TextView for large files, so layout cost stays bounded.

    Likely same root cause as the linked frozen-preview report (still open).

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions