atspi-common: register_tree panics (then aborts) when adapters become active out of order: push_adapter doesn't keep the list sorted for adapter_index's binary search
Maintainer antworten meist innerhalb von 1 Tag
Ein zugehöriger Pull Request wurde bereits gemerged.
- #821 von @DataTriny — gemerged
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- linux, rust
- Bereich
- operating-systems
Rechercherichtung
Der Fehler steckt in adapters/atspi-common/src/context.rs: push_adapter hängt an, ohne die Liste sortiert zu halten, daher übersieht die binäre Suche in adapter_index Einträge. Lies zuerst adapter_index und push_adapter, danach das unwrap in register_tree in adapter.rs. Fertig ist es, wenn Adapter, die in der Reihenfolge 1, 2, 0 eingefügt wurden, alle gefunden werden, dabei das vorgeschlagene sortierte Einfügen verwendet wird und remove_adapter den Eintrag weiterhin finden kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
What happens
AppContext in accesskit_atspi_common finds adapters with a binary search, but push_adapter appends to the end, so the list is only sorted if adapters are added in order of id:
// adapters/atspi-common/src/context.rs
pub(crate) fn adapter_index(&self, id: usize) -> Result<usize, usize> {
self.adapters.binary_search_by(|adapter| adapter.0.cmp(&id))
}
pub(crate) fn push_adapter(&mut self, id: usize, context: &Arc<Context>) {
self.adapters.push((id, Arc::clone(context)));
}
With accesskit_unix, an adapter is pushed when it goes from Pending to Active, which happens in the application's next update_if_active for that window after AT-SPI is enabled. With several windows, that is whatever order the application updates them in, not the order they were created, so the list can end up out of order (for example ids [1, 2, 0]). A binary search then misses an adapter that is in the list, and register_tree panics on
let adapter_index = app_context.adapter_index(self.id).unwrap();
while holding the app context's write lock. Unwinding drops the adapter, whose Drop calls write_app_context() on the now poisoned lock and panics again, so the process aborts:
panicked at accesskit_atspi_common-0.18.1/src/adapter.rs:461
panicked at accesskit_atspi_common-0.18.1/src/context.rs:85
panic in a destructor during cleanup
thread caused non-unwinding panic. aborting.
remove_adapter has the same problem in a quieter form: on an unsorted list it can fail to find the adapter and leave it in the list.
What should happen
Adapters can become active in any order without the lookup failing.
How to reproduce
We hit it in an application with several windows, each with an accesskit_winit adapter, on Ubuntu 26.04 (GNOME 50, Wayland and XWayland) with AT-SPI enabled, when the windows were updated in a different order than they were created. It depends on that order, so we don't have a small program that hits it every time; the lookup itself shows it. With the adapters pushed in the order 1, 2, 0:
let adapters: Vec<(usize, ())> = vec![(1, ()), (2, ()), (0, ())];
let found = adapters.binary_search_by(|adapter| adapter.0.cmp(&0));
println!("{found:?}"); // Err(0): adapter 0 is in the list but isn't found
Suggested fix
Keep the list sorted when adding:
pub(crate) fn push_adapter(&mut self, id: usize, context: &Arc<Context>) {
match self.adapter_index(id) {
Ok(index) => self.adapters[index] = (id, Arc::clone(context)),
Err(index) => self.adapters.insert(index, (id, Arc::clone(context))),
}
}
We're running with exactly this change (on 0.18.1, which egui 0.36 uses) and haven't seen the crash since. The code is the same on main (context.rs lines 109–115, adapter.rs line 463).
Versions: accesskit_atspi_common 0.18.1 through accesskit_unix 0.21.1 and accesskit_winit; also present in 0.21.0 and on main.
- Vorherrschende Sprache
- Rust
- Sterne
- 1.5k
- Forks
- 127
- Ø Merge
- 2 T. 10 Std.
- Gemergte PRs (30 T.)
- 14
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus AccessKit/accesskit
-
Document sub-treesOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 52/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 48/100
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in AccessKit/accesskit
Ähnliche Issues
-
bug dependencies kind:fix priority: P3 ready-for-agent
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
shep-pm/shep#1318 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 2 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
swc-project/swc-next#1165 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
Alive24/shea-symphony#574 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag