Closed
【缺陷报告】空指针解引用 - 文件himpi_venc.cpp - 函数GetVencJpegHuffmanParamFromPydict - 行号1215 #942
zhangjunkai9Add on  Sep 9Closed at  Sep 14
zhangjunkai9
zhangjunkai9
Sep 9 Create

缺陷信息

缺陷类型nullptrDeref (空指针解引用)
函数GetVencJpegHuffmanParamFromPydict
文件python/pyACL/himpi/himpi_venc.cpp
行号1215
置信度90%
分析模型glm-5.3-flash

缺陷描述

用户通过注册的 Python 方法 acl.himpi.venc_set_jpeg_huffman_param(pyhimpi_methods.cpp:84)传入的 dict 缺少 "dc_tables" 键时,第1214行 PyDict_GetItemString 返回 nullptr,第1215行未做任何空指针校验即传入 PyList_Size;PyList_Size 内部 PyList_Check 对空指针解引用 ob_type,段错误崩溃(本地 CPython 实测 PyList_Size(NULL) 报 access violation reading 0x0000000000000008)。第1210行 CHECK_STRUCT_DICT 仅校验外层 pyDict 非空且为 dict,未覆盖子键是否存在。用户输入即可确定性触发解释器崩溃。

事实核查

核查1:himpi_venc.cpp:1214 PyDict_GetItemString(pyDict, "dc_tables") 键缺失时返回 nullptr,1215 行未判空即传 PyList_Size,模式属实;

核查2:无防护——1210 行 CHECK_STRUCT_DICT(utils_methods.h:21-27)仅校验外层 dict 非空且为 dict,不覆盖子键存在性,PyList_Size 内部 PyList_Check 直接解引用 ob_type;

核查3:函数可达——WrapHiMpiVencSetJpegHuffmanParam(himpi_venc.cpp:1238)调用,经 pyhimpi_methods.cpp:84 注册为 acl.himpi.venc_set_jpeg_huffman_param,用户可直接调用;

核查4:触发可满足——"dc_tables" 键是否存在完全由用户 dict 决定,缺失即确定性崩溃;

本机 CPython 3.14.3 实测 PyList_Size(NULL) 报 access violation reading 0x0000000000000008,与 description 一致。

缺陷真实且用户输入可直接触发

数据流证据

Source(问题源头)

python/pyACL/himpi/himpi_venc.cpp:1234 行 WrapHiMpiVencSetJpegHuffmanParam 经 PyArg_ParseTuple(args, "iO", &chn, &pyParam) 接收用户传入 dict("dc_tables" 键是否存在完全由用户输入决定)

Sink(问题爆发点)

python/pyACL/himpi/himpi_venc.cpp:1215 行 int len = static_cast(PyList_Size(pyDcTables)) 对 nullptr 调用 PyList_Size,内部 PyList_Check 解引用空指针 ob_type,段错误崩溃(实测 access violation reading 0x8)

传播路径:

# 文件 行号 说明
1 python/pyACL/himpi/himpi_venc.cpp 1238 CHECK_NULL(GetVencJpegHuffmanParamFromPydict(pyParam, jpegHuffmanParam)) 将用户 dict 传入解析函数
2 python/pyACL/himpi/himpi_venc.cpp 1210 CHECK_STRUCT_DICT(pyDict, ...) 仅校验外层 dict 非空且为 dict,未校验子键
3 python/pyACL/himpi/himpi_venc.cpp 1214 PyObject* pyDcTables = PyDict_GetItemString(pyDict, "dc_tables") 键缺失时返回 nullptr,无判空(to_be_explored 中的 pyDcTables 取值范围已确认由用户键决定)
4 python/pyACL/himpi/himpi_venc.cpp 1215 PyList_Size(pyDcTables) 解引用 nullptr 崩溃(sink)

修复建议

PyObject* pyDcTables = PyDict_GetItemString(pyDict, "dc_tables");
if (pyDcTables == nullptr || PyList_Check(pyDcTables) == 0) {
    PyErr_SetString(PyExc_TypeError, "the dc_tables of jpeg huffman param is not a list");
    return false;
}
int len = static_cast<int>(PyList_Size(pyDcTables));
for (int i = 0; i < len; i++) {
    CHECK_BOOL(GetVencHuffmanDcTableFromPydict(PyList_GetItem(pyDcTables, i), param.dc_tables[i]));
}
likedislike
wuqifan
wuqifan
Sep 9 Comments:

问题确认,准备整改

likedislike
wuqifan
wuqifan
Sep 9 Comments:

/assign

likedislike
CANN-robotCANN-robotCollaborators
Sep 9 Assign weixin_46600764 as responsible person
wuqifanwuqifan
Sep 11 Associated pull request
CANN-robotCANN-robotCollaborators
Sep 14 Close issue
CANN-robotCANN-robotCollaborators
Sep 14 Added label: resolved
wuqifanwuqifan
Sep 22 Associated pull request