Merged
【PR】: 【FIX】pyACL相关Issues修改 #4867
wuqifanAdd on Sep 11
【PR】: 【FIX】pyACL相关Issues修改 #4867
Merged
Merged fromweixin_46600764/runtimemasterintocann/runtimemaster
Total: 4 files changed+17-5
| @@ -1212,12 +1212,18 @@ static bool GetVencJpegHuffmanParamFromPydict(PyObject* pyDict, hi_venc_jpeg_huf | |||
| 1212 | CHECK_BOOL(GetValueFromPyDict(pyDict, "reserved", param.reserved, sizeof(param.reserved) / sizeof(hi_u32))); | 1212 | CHECK_BOOL(GetValueFromPyDict(pyDict, "reserved", param.reserved, sizeof(param.reserved) / sizeof(hi_u32))); |
| 1213 | 1213 | ||
| 1214 | PyObject* pyDcTables = PyDict_GetItemString(pyDict, "dc_tables"); | 1214 | PyObject* pyDcTables = PyDict_GetItemString(pyDict, "dc_tables"); |
| 1215 | + CHECK_BOOL( | ||
| 1216 | + pyDcTables != nullptr && PyList_Check(pyDcTables) != 0, "the dc_tables argument is missing or not a list", | ||
| 1217 | + PyErr_ValueError); | ||
| 1215 | int len = static_cast<int>(PyList_Size(pyDcTables)); | 1218 | int len = static_cast<int>(PyList_Size(pyDcTables)); |
| 1216 | for (int i = 0; i < len; i++) { | 1219 | for (int i = 0; i < len; i++) { |
| 1217 | CHECK_BOOL(GetVencHuffmanDcTableFromPydict(PyList_GetItem(pyDcTables, i), param.dc_tables[i])); | 1220 | CHECK_BOOL(GetVencHuffmanDcTableFromPydict(PyList_GetItem(pyDcTables, i), param.dc_tables[i])); |
| 1218 | } | 1221 | } |
| 1219 | 1222 | ||
| 1220 | PyObject* pyAcTables = PyDict_GetItemString(pyDict, "ac_tables"); | 1223 | PyObject* pyAcTables = PyDict_GetItemString(pyDict, "ac_tables"); |
| 1224 | + CHECK_BOOL( | ||
| 1225 | + pyAcTables != nullptr && PyList_Check(pyAcTables) != 0, "the ac_tables argument is missing or not a list", | ||
| 1226 | + PyErr_ValueError); | ||
| 1221 | len = static_cast<int>(PyList_Size(pyAcTables)); | 1227 | len = static_cast<int>(PyList_Size(pyAcTables)); |
| 1222 | for (int i = 0; i < len; i++) { | 1228 | for (int i = 0; i < len; i++) { |
| 1223 | CHECK_BOOL(GetVencHuffmanAcTableFromPydict(PyList_GetItem(pyAcTables, i), param.ac_tables[i])); | 1229 | CHECK_BOOL(GetVencHuffmanAcTableFromPydict(PyList_GetItem(pyAcTables, i), param.ac_tables[i])); |
| @@ -31,20 +31,26 @@ static bool GetUnionValueFromPyDict(PyObject* pyDict, const char* keyName, aclrt | |||
| 31 | 31 | ||
| 32 | if (PyDict_GetItemString(pyValue, "moduleId") != nullptr) { | 32 | if (PyDict_GetItemString(pyValue, "moduleId") != nullptr) { |
| 33 | PyObject* pyModuleId = PyDict_GetItemString(pyValue, "moduleId"); | 33 | PyObject* pyModuleId = PyDict_GetItemString(pyValue, "moduleId"); |
| 34 | - value.moduleId = static_cast<uint16_t>(PyLong_AsUnsignedLong(pyModuleId)); | 34 | + unsigned long moduleIdVal = PyLong_AsUnsignedLong(pyModuleId); |
| 35 | CHECK_BOOL(PyErr_Occurred() == nullptr, "PyLong_AsUnsignedLong failed", PyExc_ValueError); | 35 | CHECK_BOOL(PyErr_Occurred() == nullptr, "PyLong_AsUnsignedLong failed", PyExc_ValueError); |
| 36 | + CHECK_BOOL(moduleIdVal <= UINT16_MAX, "moduleId exceeds uint16 range", PyExc_ValueError); | ||
| 37 | + value.moduleId = static_cast<uint16_t>(moduleIdVal); | ||
| 36 | } else if (PyDict_GetItemString(pyValue, "deviceId") != nullptr) { | 38 | } else if (PyDict_GetItemString(pyValue, "deviceId") != nullptr) { |
| 37 | PyObject* pyDeviceId = PyDict_GetItemString(pyValue, "deviceId"); | 39 | PyObject* pyDeviceId = PyDict_GetItemString(pyValue, "deviceId"); |
| 38 | - value.deviceId = static_cast<uint32_t>(PyLong_AsUnsignedLong(pyDeviceId)); | 40 | + unsigned long deviceIdVal = PyLong_AsUnsignedLong(pyDeviceId); |
| 39 | CHECK_BOOL(PyErr_Occurred() == nullptr, "PyLong_AsUnsignedLong failed", PyExc_ValueError); | 41 | CHECK_BOOL(PyErr_Occurred() == nullptr, "PyLong_AsUnsignedLong failed", PyExc_ValueError); |
| 42 | + CHECK_BOOL(deviceIdVal <= UINT32_MAX, "deviceId exceeds uint32 range", PyExc_ValueError); | ||
| 43 | + value.deviceId = static_cast<uint32_t>(deviceIdVal); | ||
| 40 | } else if (PyDict_GetItemString(pyValue, "rsv") != nullptr) { | 44 | } else if (PyDict_GetItemString(pyValue, "rsv") != nullptr) { |
| 41 | PyObject* pyRsv = PyDict_GetItemString(pyValue, "rsv"); | 45 | PyObject* pyRsv = PyDict_GetItemString(pyValue, "rsv"); |
| 42 | Py_ssize_t size = PyList_Size(pyRsv); | 46 | Py_ssize_t size = PyList_Size(pyRsv); |
| 43 | int loopLimit = (size < 8) ? static_cast<int>(size) : 8; | 47 | int loopLimit = (size < 8) ? static_cast<int>(size) : 8; |
| 44 | for (int i = 0; i < loopLimit; ++i) { | 48 | for (int i = 0; i < loopLimit; ++i) { |
| 45 | PyObject* pyItem = PyList_GetItem(pyRsv, i); | 49 | PyObject* pyItem = PyList_GetItem(pyRsv, i); |
| 46 | - value.rsv[i] = static_cast<uint8_t>(PyLong_AsUnsignedLong(pyItem)); | 50 | + unsigned long item = PyLong_AsUnsignedLong(pyItem); |
| 47 | CHECK_BOOL(PyErr_Occurred() == nullptr, "PyLong_AsUnsignedLong failed", PyExc_ValueError); | 51 | CHECK_BOOL(PyErr_Occurred() == nullptr, "PyLong_AsUnsignedLong failed", PyExc_ValueError); |
| 52 | + CHECK_BOOL(item <= UINT8_MAX, "the rsv element exceeds uint8 range", PyExc_ValueError); | ||
| 53 | + value.rsv[i] = static_cast<uint8_t>(item); | ||
| 48 | } | 54 | } |
| 49 | } else { | 55 | } else { |
| 50 | PyErr_SetString(PyExc_KeyError, "No valid key found in aclrtMallocAttrValue"); | 56 | PyErr_SetString(PyExc_KeyError, "No valid key found in aclrtMallocAttrValue"); |
| @@ -597,7 +597,7 @@ PyObject* WrapAclsysGetVersionStr(PyObject* /* self */, PyObject* args) | |||
| 597 | char versionStr[ACL_PKG_VERSION_MAX_SIZE] = {0}; | 597 | char versionStr[ACL_PKG_VERSION_MAX_SIZE] = {0}; |
| 598 | CHECK_NULL(PyArg_ParseTuple(args, "s", &pkgName), "acl.get_version_str args parse failed"); | 598 | CHECK_NULL(PyArg_ParseTuple(args, "s", &pkgName), "acl.get_version_str args parse failed"); |
| 599 | aclError ret = aclsysGetVersionStr(pkgName, versionStr); | 599 | aclError ret = aclsysGetVersionStr(pkgName, versionStr); |
| 600 | - return Py_BuildValue("si", versionStr, ret); | 600 | + return Py_BuildValue("s#i", versionStr, strnlen(versionStr, ACL_PKG_VERSION_MAX_SIZE), ret); |
| 601 | } | 601 | } |
| 602 | 602 | ||
| 603 | } // namespace | 603 | } // namespace |
| @@ -150,7 +150,7 @@ PyObject* WrapAclRtGetDeviceInfo(PyObject* /* self */, PyObject* args) | |||
| 150 | CHECK_NULL(PyArg_ParseTuple(args, "II", &deviceId, &attr), "acl.rt.get_device_info args parse failed"); | 150 | CHECK_NULL(PyArg_ParseTuple(args, "II", &deviceId, &attr), "acl.rt.get_device_info args parse failed"); |
| 151 | 151 | ||
| 152 | aclError ret = aclrtGetDeviceInfo(deviceId, attr, &value); | 152 | aclError ret = aclrtGetDeviceInfo(deviceId, attr, &value); |
| 153 | - return Py_BuildValue("ii", value, ret); | 153 | + return Py_BuildValue("li", value, ret); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | PyObject* WrapAclRtDeviceGetStreamPriorityRange(PyObject* /* self */, PyObject* /* args */) | 156 | PyObject* WrapAclRtDeviceGetStreamPriorityRange(PyObject* /* self */, PyObject* /* args */) |