Open
new xml.XmlPullParser(new ArrayBuffer(0)) 空指针崩溃(SIGSEGV) #2573
jizaiyiAdd on 9 hours ago
openharmony_ci
9 hours ago Comments:
9 hours ago Comments:
感谢提交Issue!关于Issue的交互操作,请访问OpenHarmony社区支持命令清单。如果有问题,请联系 [@weng-changcheng](https://gitcode.com/weng-changcheng) [@xliu-huanwei](https://gitcode.com/xliu-huanwei) [@gong_19901](https://gitcode.com/gong_19901) 。如果需要调整订阅PR、Issue的变更状态,请访问链接。
Thanks for submitting the issue. For more commands, please visit OpenHarmony Command List. If you have any questions, please refer to committer gitcode for help. If you need to change the subscription of a Pull Request or Issue, please visit the link.


9 hours ago Added label: waiting_for_assign
9 hours ago Associated pull request
问题描述 / Description
new xml.XmlPullParser(new ArrayBuffer(0))(零长 ArrayBuffer 构造解析器)导致应用 cppcrash(SIGSEGV 空指针解引用)。Bug 报告:
复现步骤 / Steps to Reproduce
import { xml } from '@kit.ArkTS'; @Entry @Component struct Index { aboutToAppear(): void { const emptyBuffer = new ArrayBuffer(0); const parser = new xml.XmlPullParser(emptyBuffer); } build(){} }真机(HUAWEI Mate 70 Pro,PLR 7.1.0.575)实测必现,进入页面即崩。
预期行为 / Expected Behavior
构造成功(空文档语义,与同模块 XmlSerializer 对空 buffer 的行为一致、与只含空白的 buffer 行为一致),后续 parse() 正常走 END_DOCUMENT 路径;任何情况下不应崩溃。
实际行为 / Actual Behavior
cppcrash:SIGSEGV(SEGV_MAPERR)@0x0000000000000388(NULL pointer dereference)。faultlog 关键帧:
寄存器 x1=0x388 与崩溃类成员偏移吻合。
环境信息 / Environment
XmlPullParserConstructor均存在该缺陷(if (data)守卫导致空 buffer 不创建 native 对象)附加信息 / Additional Context
根因分析(源码级,与 faultlog 逐帧吻合):
napi_get_arraybuffer_info返回data=nullptr;js_api_module/xml/native_module_xml.cpp的XmlPullParserConstructor中if (data)判假 → 跳过 native 对象创建 →napi_wrap_s将 nullptr 包装进 JS 对象,构造"成功"返回;js_xml.ts构造函数,编译产物 js_xml.js:366)随即调用 native 方法XmlPullParserError()检查构造错误 → napi 回调napi_unwrap_s得 nullptr 后在 nullthis上调用成员函数,拷贝xmlPullParserError_成员(std::string,设备版类布局偏移 0x388)→ SIGSEGV@0x388(对应 faultlog 帧 #00/#01/#05 及寄存器 x1=0x388)。同模块
XmlSerializerConstructor无if (data)守卫(空 buffer 正常构造、写入时报既有错误),仅 XmlPullParser 受影响。主机(Linux x86_64,真 Ark 引擎)单测环境已复现同一崩溃:修复前新增空 buffer 用例 SIGSEGV(exit=139)。
修复方案(PR 即将提交):
Parse/ParseOneTag零改动);XmlPullParserErrorunwrap 判空加固(防御性,镜像同文件ParseXml先例);