Repository navigation
Conversation
Influence: use max(faceCharaSize, jsonArray.size()) for allocation to prevent out-of-bounds write when JSON array is larger than declared size
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe fix hardens CharaDataManger::loadCharaData against CWE-787 by allocating enough space for the larger of the declared and serialized face-data sizes, bounding writes, and adding validation and allocation-failure handling. The CWE-312 plaintext-storage concern is explicitly deferred and remains unresolved. Flow diagram for safe face data loadingflowchart TD
A[loadCharaData] --> B["Read faceSize and jsonArray.size()"]
B --> C[Compute allocSize with qMax]
C --> D{allocSize <= 0}
D -->|Yes| E[Skip character]
D -->|No| F[malloc allocSize floats]
F --> G{faceChara == nullptr}
G -->|Yes| H[Skip character]
G -->|No| I[Write bounded jsonArray values]
I --> J[Store allocSize and faceChara]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charadatamanger.cpp" line_range="88" />
<code_context>
faceChara[i] = jsonArray[i].toString().toFloat();
}
- m_charaData[chara] = QPair<int, float *>(faceSize, faceChara);
+ m_charaData[chara] = QPair<int, float *>(allocSize, faceChara);
}
}
</code_context>
<issue_to_address>
**Uninitialized features corrupt templates**
When a stored entry has a positive `faceCharaSize` greater than its `faceChara` array length, `loadCharaData()` allocates `faceSize` elements but initializes only the array entries, then records `allocSize` as the template length. `saveCharaData()` serializes the uninitialized tail, and `getCharaData()` copies it for verification, corrupting templates and producing unreliable recognition results.
Initialize every allocated element before recording `allocSize` as the template length.
</issue_to_address>| faceChara[i] = jsonArray[i].toString().toFloat(); | ||
| } | ||
| m_charaData[chara] = QPair<int, float *>(faceSize, faceChara); | ||
| m_charaData[chara] = QPair<int, float *>(allocSize, faceChara); |
There was a problem hiding this comment.
🟡 Medium · Uninitialized features corrupt templates
When a stored entry has a positive faceCharaSize greater than its faceChara array length, loadCharaData() allocates faceSize elements but initializes only the array entries, then records allocSize as the template length. saveCharaData() serializes the uninitialized tail, and getCharaData() copies it for verification, corrupting templates and producing unreliable recognition results.
Initialize every allocated element before recording allocSize as the template length.
Prompt for AI agents
In `charadatamanger.cpp` at line 88:
**Uninitialized features corrupt templates**
When a stored entry has a positive `faceCharaSize` greater than its `faceChara` array length, `loadCharaData()` allocates `faceSize` elements but initializes only the array entries, then records `allocSize` as the template length. `saveCharaData()` serializes the uninitialized tail, and `getCharaData()` copies it for verification, corrupting templates and producing unreliable recognition results.
Initialize every allocated element before recording `allocSize` as the template length.
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['建议将 malloc 替换为 calloc,或在使用 malloc 后通过 memset 显式清零未写入部分,确保所有分配的内存都被正确初始化'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['建议使用 calloc 替代 malloc 以零初始化缓冲区,进一步消除未初始化内存读取的潜在风险'] 💡 改进建议代码示例// 推荐使用 calloc 替代 malloc,确保缓冲区零初始化
int allocSize = qMax(faceSize, jsonArray.size());
if (allocSize <= 0) {
qWarning() << "Invalid face data size, skipping:" << chara;
continue;
}
float *faceChara = static_cast<float *>(
calloc(static_cast<unsigned long>(allocSize), sizeof(float)));
if (faceChara == nullptr) {
qWarning() << "Failed to allocate face data, skipping:" << chara;
continue;
}
for (int i = 0; i < jsonArray.size() && i < allocSize; i++) {
faceChara[i] = jsonArray[i].toString().toFloat();
}
m_charaData[chara] = QPair<int, float *>(allocSize, faceChara);本报告由 AI 代码审查工具自动生成 |
Security Fix
CWE-787: Out-of-bounds Write (charadatamanger.cpp:83)
CWE-312: Sensitive Data in Plaintext (design-level, deferred)
Summary by Sourcery
Harden character-data loading against invalid sizes, allocation failures, and out-of-bounds writes.
Bug Fixes: