napi backend: unguarded selector dispatch turns unrecognized selector into process abort (NSException cannot unwind through ffi_call)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 40/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- ios, macos, objective-c
- 领域
- backend
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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/runtimesmain(verified identical at5b697b39)- Generic napi backend,
TARGET_PLATFORM=macos, arm64; same code path ships in the iOS napi runtime.
- 主要语言
- C++
- 星标
- 27
- 派生
- 4
- 平均合并
- 5 天 11 小时
- 30 天内合并 PR
- 12
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NativeScript/runtimes 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 30/100
NativeScript/runtimes#111 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 22/100
NativeScript/runtimes#110 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 32/100
NativeScript/runtimes#109 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 18/100
NativeScript/runtimes#108 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 42/100
NativeScript/runtimes#106 ·
维护者通常 1 天内回复
查看 NativeScript/runtimes 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 70/100
EchoTools/nevr-runtime#2042 ·
维护者通常 1 天内回复
-
Download size and speed show scientific notation between 1000 and 1023 units可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1 小时以内 新手友好度 88/100
kiwix/kiwix-desktop#1570 ·
维护者通常 1 天内回复
-
Device Request
难度 2/5 半天 新手友好度 62/100
dresden-elektronik/deconz-rest-plugin#8686 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
aminya/project_options#303 ·