Merged
fix: 校验 PyACL 批量 VPC ROI 数组长度 #5681
KaranocaVeAdd on Oct 20
fix: 校验 PyACL 批量 VPC ROI 数组长度 #5681
Merged
Total: 1 files changed+24-0
| @@ -64,6 +64,23 @@ static bool ProcessArray(PyObject& numList, uint32_t& numArray, int size) | |||
| 64 | return true; | 64 | return true; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | +static bool CheckBatchRoiArrayLength(const std::vector<uint32_t>& roiNums, size_t batchSize, size_t roiArraySize) | ||
| 68 | +{ | ||
| 69 | + size_t totalRoiCount = 0; | ||
| 70 | + for (size_t i = 0; i < batchSize; ++i) { | ||
| 71 | + if (roiNums[i] > roiArraySize - totalRoiCount) { | ||
| 72 | + PyErr_SetString(PyExc_ValueError, "the roiNums total does not match the ROI array length"); | ||
| 73 | + return false; | ||
| 74 | + } | ||
| 75 | + totalRoiCount += roiNums[i]; | ||
| 76 | + } | ||
| 77 | + if (totalRoiCount != roiArraySize) { | ||
| 78 | + PyErr_SetString(PyExc_ValueError, "the roiNums total does not match the ROI array length"); | ||
| 79 | + return false; | ||
| 80 | + } | ||
| 81 | + return true; | ||
| 82 | +} | ||
| 83 | + | ||
| 67 | PyObject* WrapAclDvppVpcBatchCropAsync(PyObject* /* self */, PyObject* args) | 84 | PyObject* WrapAclDvppVpcBatchCropAsync(PyObject* /* self */, PyObject* args) |
| 68 | { | 85 | { |
| 69 | acldvppChannelDesc* channelDesc = nullptr; | 86 | acldvppChannelDesc* channelDesc = nullptr; |
| @@ -87,6 +104,7 @@ PyObject* WrapAclDvppVpcBatchCropAsync(PyObject* /* self */, PyObject* args) | |||
| 87 | 104 | ||
| 88 | std::vector<uint32_t> roiNums(size + 1); | 105 | std::vector<uint32_t> roiNums(size + 1); |
| 89 | CHECK_NULL(ProcessArray(*roiNumsList, *(roiNums.data()), size)) | 106 | CHECK_NULL(ProcessArray(*roiNumsList, *(roiNums.data()), size)) |
| 107 | + CHECK_NULL(CheckBatchRoiArrayLength(roiNums, static_cast<size_t>(size), static_cast<size_t>(cropSize))); | ||
| 90 | std::vector<acldvppRoiConfig*> cropAreas(cropSize + 1, nullptr); | 108 | std::vector<acldvppRoiConfig*> cropAreas(cropSize + 1, nullptr); |
| 91 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasList, cropSize, cropAreas.data())); | 109 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasList, cropSize, cropAreas.data())); |
| 92 | 110 | ||
| @@ -149,6 +167,7 @@ PyObject* WrapAclDvppVpcBatchCropAndPasteAsync(PyObject* /* self */, PyObject* a | |||
| 149 | CHECK_NULL(CheckArgsAndGetSize(*roiNumsList, *cropAreasList, *pasteAreasList, size, cropSize)); | 167 | CHECK_NULL(CheckArgsAndGetSize(*roiNumsList, *cropAreasList, *pasteAreasList, size, cropSize)); |
| 150 | std::vector<uint32_t> roiNums(size + 1); | 168 | std::vector<uint32_t> roiNums(size + 1); |
| 151 | CHECK_NULL(ProcessArray(*roiNumsList, *(roiNums.data()), size)); | 169 | CHECK_NULL(ProcessArray(*roiNumsList, *(roiNums.data()), size)); |
| 170 | + CHECK_NULL(CheckBatchRoiArrayLength(roiNums, static_cast<size_t>(size), static_cast<size_t>(cropSize))); | ||
| 152 | std::vector<acldvppRoiConfig*> cropAreas(cropSize + 1, nullptr); | 171 | std::vector<acldvppRoiConfig*> cropAreas(cropSize + 1, nullptr); |
| 153 | std::vector<acldvppRoiConfig*> pasteAreas(cropSize + 1, nullptr); | 172 | std::vector<acldvppRoiConfig*> pasteAreas(cropSize + 1, nullptr); |
| 154 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasList, cropSize, cropAreas.data())); | 173 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasList, cropSize, cropAreas.data())); |
| @@ -408,6 +427,7 @@ PyObject* WrapAclDvppVpcBatchCropResizeAsync(PyObject* /* self */, PyObject* arg | |||
| 408 | 427 | ||
| 409 | CHECK_NULL(PyList_Check(cropAreasObj), "argument 5 is not list"); | 428 | CHECK_NULL(PyList_Check(cropAreasObj), "argument 5 is not list"); |
| 410 | ssize_t cropAreasSize = PyList_Size(cropAreasObj); | 429 | ssize_t cropAreasSize = PyList_Size(cropAreasObj); |
| 430 | + CHECK_NULL(CheckBatchRoiArrayLength(roiNums, static_cast<size_t>(roiNumsSize), static_cast<size_t>(cropAreasSize))); | ||
| 411 | std::vector<acldvppRoiConfig*> cropAreas(cropAreasSize + 1, nullptr); | 431 | std::vector<acldvppRoiConfig*> cropAreas(cropAreasSize + 1, nullptr); |
| 412 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasObj, static_cast<int>(cropAreasSize), cropAreas.data())); | 432 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasObj, static_cast<int>(cropAreasSize), cropAreas.data())); |
| 413 | 433 | ||
| @@ -461,11 +481,13 @@ PyObject* WrapAclDvppVpcBatchCropResizePasteAsync(PyObject* /* self */, PyObject | |||
| 461 | 481 | ||
| 462 | CHECK_NULL(PyList_Check(cropAreasObj), "argument 5 is not list"); | 482 | CHECK_NULL(PyList_Check(cropAreasObj), "argument 5 is not list"); |
| 463 | ssize_t cropAreasSize = PyList_Size(cropAreasObj); | 483 | ssize_t cropAreasSize = PyList_Size(cropAreasObj); |
| 484 | + CHECK_NULL(CheckBatchRoiArrayLength(roiNums, static_cast<size_t>(roiNumsSize), static_cast<size_t>(cropAreasSize))); | ||
| 464 | std::vector<acldvppRoiConfig*> cropAreas(cropAreasSize + 1, nullptr); | 485 | std::vector<acldvppRoiConfig*> cropAreas(cropAreasSize + 1, nullptr); |
| 465 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasObj, static_cast<int>(cropAreasSize), cropAreas.data())); | 486 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasObj, static_cast<int>(cropAreasSize), cropAreas.data())); |
| 466 | 487 | ||
| 467 | CHECK_NULL(PyList_Check(pasteAreasObj), "argument 6 is not list"); | 488 | CHECK_NULL(PyList_Check(pasteAreasObj), "argument 6 is not list"); |
| 468 | ssize_t pasteAreasSize = PyList_Size(pasteAreasObj); | 489 | ssize_t pasteAreasSize = PyList_Size(pasteAreasObj); |
| 490 | + CHECK_NULL(pasteAreasSize == cropAreasSize, "cropAreas and pasteAreas lengths differ", PyExc_ValueError); | ||
| 469 | std::vector<acldvppRoiConfig*> pasteAreas(pasteAreasSize + 1, nullptr); | 491 | std::vector<acldvppRoiConfig*> pasteAreas(pasteAreasSize + 1, nullptr); |
| 470 | CHECK_NULL(ConvertPyListToPtrArray(pasteAreasObj, static_cast<int>(pasteAreasSize), pasteAreas.data())); | 492 | CHECK_NULL(ConvertPyListToPtrArray(pasteAreasObj, static_cast<int>(pasteAreasSize), pasteAreas.data())); |
| 471 | 493 | ||
| @@ -499,11 +521,13 @@ PyObject* WrapAclDvppVpcBatchCropResizeMakeBorderAsync(PyObject* /* self */, PyO | |||
| 499 | 521 | ||
| 500 | CHECK_NULL(PyList_Check(cropAreasObj), "the fifth argument is not list"); | 522 | CHECK_NULL(PyList_Check(cropAreasObj), "the fifth argument is not list"); |
| 501 | ssize_t cropAreasSize = PyList_Size(cropAreasObj); | 523 | ssize_t cropAreasSize = PyList_Size(cropAreasObj); |
| 524 | + CHECK_NULL(CheckBatchRoiArrayLength(roiNums, static_cast<size_t>(roiNumsSize), static_cast<size_t>(cropAreasSize))); | ||
| 502 | std::vector<acldvppRoiConfig*> cropAreas(cropAreasSize + 1, nullptr); | 525 | std::vector<acldvppRoiConfig*> cropAreas(cropAreasSize + 1, nullptr); |
| 503 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasObj, static_cast<int>(cropAreasSize), cropAreas.data())); | 526 | CHECK_NULL(ConvertPyListToPtrArray(cropAreasObj, static_cast<int>(cropAreasSize), cropAreas.data())); |
| 504 | 527 | ||
| 505 | CHECK_NULL(PyList_Check(borderCfgsObj), "the sixth argument is not list"); | 528 | CHECK_NULL(PyList_Check(borderCfgsObj), "the sixth argument is not list"); |
| 506 | ssize_t borderCfgsSize = PyList_Size(borderCfgsObj); | 529 | ssize_t borderCfgsSize = PyList_Size(borderCfgsObj); |
| 530 | + CHECK_NULL(borderCfgsSize == cropAreasSize, "cropAreas and borderCfgs lengths differ", PyExc_ValueError); | ||
| 507 | std::vector<acldvppBorderConfig*> borderCfgs(borderCfgsSize + 1, nullptr); | 531 | std::vector<acldvppBorderConfig*> borderCfgs(borderCfgsSize + 1, nullptr); |
| 508 | CHECK_NULL(ConvertPyListToPtrArray(borderCfgsObj, static_cast<int>(borderCfgsSize), borderCfgs.data())); | 532 | CHECK_NULL(ConvertPyListToPtrArray(borderCfgsObj, static_cast<int>(borderCfgsSize), borderCfgs.data())); |
| 509 | 533 | ||