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

缺陷信息

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

缺陷描述

用户 dict 缺少 "ac_tables" 键时,第1220行 PyDict_GetItemString 返回 nullptr,第1221行未判空即传入 PyList_Size,内部 PyList_Check 解引用空指针 ob_type,段错误崩溃(实测 access violation reading 0x0000000000000008)。与第1215行 "dc_tables" 键缺失崩溃为同一函数内的同类缺陷,经 acl.himpi.venc_set_jpeg_huffman_param 由用户输入直接触发。

事实核查

核查1:himpi_venc.cpp:1220 PyDict_GetItemString(pyDict, "ac_tables") 键缺失时返回 nullptr,1221 行未判空即传 PyList_Size,模式属实,与 1215 行 "dc_tables" 缺失崩溃为同一函数同类缺陷;

核查2:无防护——CHECK_STRUCT_DICT(utils_methods.h:21-27)仅校验外层 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:触发可满足——"ac_tables" 键存在性由用户输入决定,缺失即确定性崩溃;

本机 CPython 3.14.3 实测 PyList_Size(NULL) 报 access violation reading 0x0000000000000008。

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

数据流证据

Source(问题源头)

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

Sink(问题爆发点)

python/pyACL/himpi/himpi_venc.cpp:1221 行 len = static_cast(PyList_Size(pyAcTables)) 对 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 1220 PyObject* pyAcTables = PyDict_GetItemString(pyDict, "ac_tables") 键缺失时返回 nullptr,无判空(to_be_explored 中的 pyAcTables 取值范围已确认由用户键决定)
3 python/pyACL/himpi/himpi_venc.cpp 1221 PyList_Size(pyAcTables) 解引用 nullptr 崩溃(sink)

修复建议

PyObject* pyAcTables = PyDict_GetItemString(pyDict, "ac_tables");
if (pyAcTables == nullptr || PyList_Check(pyAcTables) == 0) {
    PyErr_SetString(PyExc_TypeError, "the ac_tables of jpeg huffman param is not a list");
    return false;
}
len = static_cast<int>(PyList_Size(pyAcTables));
for (int i = 0; i < len; i++) {
    CHECK_BOOL(GetVencHuffmanAcTableFromPydict(PyList_GetItem(pyAcTables, i), param.ac_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