[iOS][Fabric] `RCTSwitchComponentView onChange:` dereferences `_eventEmitter` without a null check (EXC_BAD_ACCESS after view recycle)
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- objective-c, react-native
- Ambito
- mobile
Direzione di ricerca
Leggi React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm, in particolare onChange: e la gestione del riciclo nelle vicinanze citata nell’issue. Confronta i controlli sull’event emitter nelle viste dei componenti fratelli menzionate nel report, poi verifica i test pertinenti di Switch o aggiungi una copertura per una vista riciclata se i test esistenti fanno emergere questo percorso. Il lavoro è completo quando onChange: gestisce in sicurezza un emitter azzerato e il comportamento esistente di Switch resta coperto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
- react-native 0.88.0 (first seen on 0.86.0; the file is byte-identical in both), New Architecture
- iOS 26.5.2 device (production crash), same code path on iOS 27
- Expo SDK 58 (not involved)
Description
-[RCTSwitchComponentView onChange:] (React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm:105-114) ends with
static_cast<const SwitchEventEmitter &>(*_eventEmitter) // line 113
.onChange(SwitchEventEmitter::OnChange{.value = static_cast<bool>(sender.on)});
with no check that _eventEmitter is set. RCTViewComponentView -prepareForRecycle resets it (RCTViewComponentView.mm:779, _eventEmitter.reset();), while _props stays valid, so the earlier *_props dereference does not fail.
Production crash (0.86.0, line 114 of that version), iOS 26.5.2:
EXC_BAD_ACCESS (SIGSEGV) KERN_INVALID_ADDRESS at 0x0000000000000030
0 React std::weak_ptr<EventDispatcher const>::lock()
1 React EventEmitter::dispatchEvent(...)
4 React SwitchEventEmitter::onChange(...)
5 React -[RCTSwitchComponentView onChange:]
6 UIKitCore -[UIApplication sendAction:to:from:forEvent:]
9 UIKitCore -[UISwitchModernVisualElement sendStateChangeActions]
11 UIKitCore -[UISwitchModernVisualElement _handleLongPressWithGestureLocationInBounds:...]
12 UIKitCore -[_UIAfterCACommitBlock run]
0x30 is a null this plus the eventDispatcher_ offset in EventEmitter.
Reproduction
Intermittent, not reproduced on demand. Conditions: iOS 26+, where the redesigned UISwitch (UISwitchModernVisualElement) delivers the state-change action from a deferred _UIAfterCACommitBlock instead of synchronously on touch-up (seen when the switch is dragged or long-pressed rather than tapped). If React re-renders and recycles the Switch view between the gesture ending and that block running, prepareForRecycle has already cleared _eventEmitter and onChange: runs on the recycled view.
Root cause
Missing null guard. Sibling components in the same directory tree already have it: RCTScrollViewComponentView, RCTImageComponentView, RCTModalHostViewComponentView, RCTVirtualViewComponentView (if (!_eventEmitter) { return; }), and RCTTextInputComponentView tests _eventEmitter before use at several sites. Switch is the outlier.
Proposed fix
--- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm
+++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm
@@ -110,6 +110,9 @@ - (void)onChange:(UISwitch *)sender
return;
}
+ if (!_eventEmitter) {
+ return;
+ }
static_cast<const SwitchEventEmitter &>(*_eventEmitter)
.onChange(SwitchEventEmitter::OnChange{.value = static_cast<bool>(sender.on)});
}
We carry this as a local patch. Dropping the event is the right behaviour: the view has been recycled and no longer represents that React node.
Disclosure: drafted with AI assistance (Claude) from a patch we carry locally; code references were checked against the published package sources. Happy to clarify or open a PR.
- Lingua principale
- C++
- Stelle
- 127k
- Fork
- 25.3k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di react/react-native
-
Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android appForse già presa @YevheniiKotyrlo l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
react/react-native#59006 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Fabric TextInput: prepareForRecycle leaves stale inputAccessoryViewButtonLabel (empty Done bar)Forse già presa @jkasprzyk17 l’ha presa 5 giorni fa. ApertaNeeds: Author Feedback Needs: Repro
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
react/react-native#58952 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
[iOS][Fabric] TextInput drops a keystroke right after the first character typed into an empty field (_textOf:equals: compares attributes of a focused field)Forse già presa Una pull request collegata a questa issue è aperta o già unita. ApertaNeeds: Attention Needs: Repro
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
react/react-native#58904 · 3 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Needs: Author Feedback Needs: Repro
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
react/react-native#58659 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Needs: Author Feedback Needs: Repro
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
react/react-native#58621 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di react/react-native
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ROCm/rocm-libraries#14027 ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
Qiskit/qiskit-aer#2487 ·
I maintainer di solito rispondono entro 1 giorno
-
GUI
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
qbittorrent/qBittorrent#25104 ·
I maintainer di solito rispondono entro 2 giorni
-
P2: A timed rotation maneuver does nothing on a ship that had an earlier timed lateral maneuverAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
scp-fs2open/fs2open.github.com#7914 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 2 giorni