napi backend: unguarded selector dispatch turns unrecognized selector into process abort (NSException cannot unwind through ffi_call)

Offen
#107 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
40/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
ios, macos, objective-c
Bereich
backend

Rechercherichtung

Start in NativeScript/ffi/napi/ClassMember.mm, comparing tryObjCNapiDispatch and objcNativeCall against the respondsToSelector: guard in NativeScript/ffi/shared/jsi/NativeApiJsiInvocation.h (callObjCSelector). Reproduce by calling an instance member the receiver lacks, such as NSView.alloc().init().autoscroll, on a generic-napi macOS build. Done when that call throws a JS error instead of aborting, and resolveInstanceMethod: receivers still dispatch.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary

The napi backend dispatches objc_msgSend without verifying the receiver implements the selector. When metadata names a member the concrete receiver lacks — phantom metagen entries (#106), optional protocol members, SDK drift — the send enters ___forwarding___ → doesNotRecognizeSelector: → objc_exception_throw. The NSException cannot unwind through ffi_call's frames, so the process dies in __cxxabiv1::failed_throw (SIGABRT) before the surrounding @try/@catch — or any JS try/catch — can run.

The jsi backend already guards the same dispatch with respondsToSelector: (NativeScript/ffi/shared/jsi/NativeApiJsiInvocation.h, callObjCSelector). NativeScript/ffi/napi/ClassMember.mm — both tryObjCNapiDispatch (generated-invoker path) and objcNativeCall (ffi/super path) — does not.

Reproduction

macOS arm64, generic-napi build (-DTARGET_ENGINE=none -DNS_FFI_BACKEND=napi), metadata carrying a phantom member (see #106):

NSView.alloc().init().autoscroll

→ -[NSView isAutoscroll]: unrecognized selector sent to instance → libc++abi: terminating due to uncaught exception of type NSException → SIGABRT. More generally, any unrecognized selector reached through bridged dispatch aborts the process rather than raising a JS error.

Expected

Verify respondsToSelector: before self-targeted dispatch (one check per call) and rethrow the unrecognized-selector failure as a JS error — matching the jsi backend's tradeoff: forwarding-only receivers get a JS error, while resolveInstanceMethod: receivers still work because the check triggers method resolution.

Environment

  • NativeScript/runtimes main (verified identical at 5b697b39)
  • Generic napi backend, TARGET_PLATFORM=macos, arm64; same code path ships in the iOS napi runtime.
Vorherrschende Sprache
C++
Sterne
27
Forks
5
Ø Merge
5 T. 11 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus NativeScript/runtimes

Alle Issues in NativeScript/runtimes

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.