react / react/react-native

[Android][0.87.1] numberOfLines crashes when a decorated nested Text range is outside the truncated layout

Aperta
#58,356 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs: Triage :mag: Platform: Android
Lingua principale
C++
Stelle
127k
Fork
25.3k
Merge medio
1g 23h
PR unite (30g)
4

Descrizione

Description

On Android, a Text with numberOfLines can crash the application when a nested Text has textDecorationLine: 'underline' or 'line-through' and the decorated range starts after content that is omitted by the truncated native layout.

Both decoration types fail in the same native drawing path. This is a fatal main-thread exception rather than a redbox or a JavaScript error.

Additional context

drawSpannedDecoration() obtains start and end from the complete Spanned text, then calls layout.getPrimaryHorizontal(start/end). With numberOfLines, the native Layout can end before the decorated span. In this example, the span starts at offset 60 while the only layout line ends at offset 19, so Android throws before drawing the decoration.

Underline and line-through share this drawing function, which explains why both variants crash. A safe fix likely needs to skip or clip decoration ranges to offsets represented by the truncated Layout before calling getPrimaryHorizontal.

Relevant React Native 0.87.1 source:

This may be adjacent to #57900, which reports Android text-decoration rendering differences. This report is specifically about a fatal out-of-bounds exception caused by a decorated range outside a truncated layout.

Steps to reproduce
  1. Clone [react-native-text-decoration-crash-repro](https://github.com/ouabing/react-native-text-decoration-crash-repro).
  2. npm install.
  3. npm start.
  4. npm run android.
  5. Press Reproduce with underline or Reproduce with line-through.

The minimal trigger is:

<Text numberOfLines={1} ellipsizeMode="tail">
  {'Visible first line\n\nThird paragraph\n\nHidden decorated text: '}
  <Text style={{textDecorationLine: 'line-through'}}>
    decorated text outside the one-line layout
  </Text>
</Text>

Changing line-through to underline reproduces the same crash. Removing numberOfLines, the line breaks, or textDecorationLine avoids it.

React Native Version

0.87.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.6.1
  CPU: Apple M1 Pro (arm64)
Binaries:
  Node: 22.13.1
  npm: 10.9.2
  Java: 17.0.16
npmPackages:
  react: 19.2.3
  react-native: 0.87.1
Android:
  Android 14 / API 34 arm64 emulator
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
FATAL EXCEPTION: main
Process: com.rntextdecorationcrashrepro
java.lang.IndexOutOfBoundsException: offset(60) should be less than line limit(19)
    at android.text.TextLine.measure(TextLine.java:389)
    at android.text.Layout.getHorizontal(Layout.java:1390)
    at android.text.Layout.getHorizontal(Layout.java:1366)
    at android.text.Layout.getPrimaryHorizontal(Layout.java:1336)
    at android.text.Layout.getPrimaryHorizontal(Layout.java:1325)
    at com.facebook.react.views.text.TextDecorationStyleKt.drawSpannedDecoration(TextDecorationStyle.kt:182)
    at com.facebook.react.views.text.internal.span.ReactUnderlineSpan.onDraw(ReactUnderlineSpan.kt:31)
    at com.facebook.react.views.text.ReactTextView.drawTextEffects(ReactTextView.java:283)
    at com.facebook.react.views.text.ReactTextView.onDraw(ReactTextView.java:227)
MANDATORY Reproducer

https://github.com/ouabing/react-native-text-decoration-crash-repro

Screenshots and Videos

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da TextDecorationStyle.kt, in particolare dalle chiamate a getPrimaryHorizontal, poi esamina ReactUnderlineSpan.kt e ReactStrikethroughSpan.kt per tracciare entrambi i percorsi di decorazione. Esegui il reproducer obbligatorio con npm install, npm start e npm run android e verifica che sia underline sia line-through non vadano più in crash quando il relativo intervallo decorato si trova oltre il layout troncato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, kotlin, react-native
Ambito
mobile
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
75/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.