Repository navigation
fix: fix 5 fuzz test security issues in devicemanager - #982
Conversation
Reviewer's GuideImplementationGuard SMART-device parsing against malformed lines before accessing the third path component.
Prevent display-ratio calculation from dividing by zero by rejecting zero dimensions and guarding the GCD base case.
Check the scaled storage size is within the quint64 range before converting it.
Widen hexadecimal accumulation and cap the processed input length to avoid signed overflow.
TestsUpdate the thread pool task test file’s SPDX copyright range.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp" line_range="173" />
<code_context>
}
- diskBytesSize = static_cast<quint64>(diskSizeFloat * multiplier);
+ double result = diskSizeFloat * multiplier;
+ if (result < 0.0 || result > static_cast<double>(std::numeric_limits<quint64>::max())) {
+ qCDebug(appLog) << "convertToBytes, result out of range, clamping to 0";
+ return 0;
</code_context>
<issue_to_address>
**Out-of-range sizes reach the cast**
When the computed result is exactly 2^64, `static_cast<double>(std::numeric_limits<quint64>::max())` rounds up to 2^64, so the `>` check passes and `static_cast<quint64>(result)` converts an out-of-range value, causing undefined behavior and an unreliable disk size.
Reject results greater than or equal to 2^64 before casting to `quint64`.
</issue_to_address>
### Comment 2
<location path="deepin-devicemanager/src/Tool/EDIDParser.cpp" line_range="492-497" />
<code_context>
int i;
- int v = 0;
- for (i = 0; i < strHex.length(); i++) {
+ qint64 v = 0;
+ int len = strHex.length();
+ if (len > 16) {
+ len = 16;
+ }
+ for (i = 0; i < len; i++) {
v *= 16;
v += hex2(strHex[i].toLatin1());
</code_context>
<issue_to_address>
**Large hex values overflow**
When the first 16 hex digits represent a value greater than `qint64`'s maximum, `hexToDec` accumulates the digits in signed `qint64`, so the multiplication or addition overflows and invokes undefined behavior; callers receive an unreliable result.
Detect values outside the `qint64` range before accumulating them and handle them without signed overflow.
Also at `deepin-devicemanager/src/Tool/EDIDParser.cpp:498-499`.
</issue_to_address>
### Comment 3
<location path="deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp" line_range="518-520" />
<code_context>
if (match.hasMatch()) {
int width = match.captured(1).toInt();
int height = match.captured(2).toInt();
+ if (width == 0 || height == 0) {
+ qCDebug(appLog) << "Width or height is zero, skip ratio calculation";
+ return;
+ }
int gys = gcd(width, height);
</code_context>
<issue_to_address>
**Previous display ratio remains**
When the same `DeviceMonitor` processes a zero-dimension resolution after a valid one, `caculateScreenRatio()` returns without clearing `m_AspectRatio`, so the previous resolution's ratio remains visible to callers.
Clear `m_AspectRatio` before returning for a zero-sized resolution.
</issue_to_address>
### Comment 4
<location path="deepin-devicemanager/src/Tool/EDIDParser.cpp" line_range="494-497" />
<code_context>
- for (i = 0; i < strHex.length(); i++) {
+ qint64 v = 0;
+ int len = strHex.length();
+ if (len > 16) {
+ len = 16;
+ }
+ for (i = 0; i < len; i++) {
v *= 16;
v += hex2(strHex[i].toLatin1());
</code_context>
<issue_to_address>
**Long values lose trailing digits**
When a hex string longer than 16 characters has significant digits only after the first 16, `hexToDec` processes only the first 16 characters, so a longer value with leading zeroes and significant digits afterward is silently converted to a different number; callers see an incorrect result instead of a valid conversion or an explicit rejection.
Reject overlength input explicitly, or otherwise preserve its significant digits without overflowing the accumulator.
</issue_to_address>| } | ||
| diskBytesSize = static_cast<quint64>(diskSizeFloat * multiplier); | ||
| double result = diskSizeFloat * multiplier; | ||
| if (result < 0.0 || result > static_cast<double>(std::numeric_limits<quint64>::max())) { |
There was a problem hiding this comment.
🟡 Medium · Out-of-range sizes reach the cast
When the computed result is exactly 2^64, static_cast<double>(std::numeric_limits<quint64>::max()) rounds up to 2^64, so the > check passes and static_cast<quint64>(result) converts an out-of-range value, causing undefined behavior and an unreliable disk size.
Reject results greater than or equal to 2^64 before casting to quint64.
Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp` at line 173:
**Out-of-range sizes reach the cast**
When the computed result is exactly 2^64, `static_cast<double>(std::numeric_limits<quint64>::max())` rounds up to 2^64, so the `>` check passes and `static_cast<quint64>(result)` converts an out-of-range value, causing undefined behavior and an unreliable disk size.
Reject results greater than or equal to 2^64 before casting to `quint64`.| if (width == 0 || height == 0) { | ||
| qCDebug(appLog) << "Width or height is zero, skip ratio calculation"; | ||
| return; |
There was a problem hiding this comment.
🟡 Medium · Previous display ratio remains
When the same DeviceMonitor processes a zero-dimension resolution after a valid one, caculateScreenRatio() returns without clearing m_AspectRatio, so the previous resolution's ratio remains visible to callers.
Clear m_AspectRatio before returning for a zero-sized resolution.
Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp` at lines 518-520:
**Previous display ratio remains**
When the same `DeviceMonitor` processes a zero-dimension resolution after a valid one, `caculateScreenRatio()` returns without clearing `m_AspectRatio`, so the previous resolution's ratio remains visible to callers.
Clear `m_AspectRatio` before returning for a zero-sized resolution.| if (len > 16) { | ||
| len = 16; | ||
| } | ||
| for (i = 0; i < len; i++) { |
There was a problem hiding this comment.
🟡 Medium · Long values lose trailing digits
When a hex string longer than 16 characters has significant digits only after the first 16, hexToDec processes only the first 16 characters, so a longer value with leading zeroes and significant digits afterward is silently converted to a different number; callers see an incorrect result instead of a valid conversion or an explicit rejection.
Reject overlength input explicitly, or otherwise preserve its significant digits without overflowing the accumulator.
Prompt for AI agents
In `deepin-devicemanager/src/Tool/EDIDParser.cpp` at lines 494-497:
**Long values lose trailing digits**
When a hex string longer than 16 characters has significant digits only after the first 16, `hexToDec` processes only the first 16 characters, so a longer value with leading zeroes and significant digits afterward is silently converted to a different number; callers see an incorrect result instead of a valid conversion or an explicit rejection.
Reject overlength input explicitly, or otherwise preserve its significant digits without overflowing the accumulator.1928656 to
b6573f3
Compare
b6573f3 to
75fda5e
Compare
75fda5e to
88248a6
Compare
|
TAG Bot TAG: 6.0.76 |
1. Root cause: gcd() did not guard b==0 causing SIGFPE on zero input; hexToDec() used int accumulation causing signed overflow on long hex; convertToBytes() cast unchecked double to quint64 causing UB on large values; loadSgSmartCtlInfoToCache() accessed words[2] without size check 2. Fix: add b==0 guard in gcd() and zero-value filter in caculateScreenRatio(); widen hexToDec() to qint64 with 15-char cap; validate double range before static_cast in convertToBytes(); add words.size()<3 guard in loadSgSmartCtlInfoToCache(); update SPDX copyright year to 2026 3. Impact: eliminates divide-by-zero, integer overflow, and OOB read paths under fuzz input; no behavior change for valid inputs Influence: 1. Test screen ratio calculation with zero/empty resolution strings 2. Test hexToDec with long hex strings exceeding INT_MAX 3. Test convertToBytes with extremely large size values 4. Test loadSgSmartCtlInfoToCache with malformed line input fix: 修复设备管理器5个模糊测试安全问题 1. 根因:gcd()未处理b==0导致除零崩溃;hexToDec()使用int累加长十六进制 字符串溢出;convertToBytes()未校验double转quint64越界; loadSgSmartCtlInfoToCache()未检查words[2]越界 2. 方案:gcd()入口加b==0守卫,caculateScreenRatio()过滤零值; hexToDec()扩宽为qint64并限制15字符;convertToBytes()转换前校验 数值范围;loadSgSmartCtlInfoToCache()加words.size()<3检查; 更新SPDX版权年份至2026 3. 影响:消除模糊测试输入下的除零、整数溢出、越界读取路径,对正常 输入无行为变化 Influence: 1. 测试零值/空分辨率字符串的屏幕比例计算 2. 测试超长十六进制字符串的hexToDec转换 3. 测试超大数值的convertToBytes转换 4. 测试格式异常行的loadSgSmartCtlInfoToCache处理 PMS: BUG-383515
88248a6 to
4a8e089
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liyigang1, max-lvs 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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
fix: fix 5 fuzz test security issues in devicemanager
hexToDec() used int accumulation causing signed overflow on long hex;
convertToBytes() cast unchecked double to quint64 causing UB on large
values; loadSgSmartCtlInfoToCache() accessed words[2] without size check
caculateScreenRatio(); widen hexToDec() to qint64 with 16-char cap;
validate double range before static_cast in convertToBytes(); add
words.size()<3 guard in loadSgSmartCtlInfoToCache()
paths under fuzz input; no behavior change for valid inputs
Influence:
fix: 修复设备管理器5个模糊测试安全问题
字符串溢出;convertToBytes()未校验double转quint64越界;
loadSgSmartCtlInfoToCache()未检查words[2]越界
hexToDec()扩宽为qint64并限制16字符;convertToBytes()转换前校验
数值范围;loadSgSmartCtlInfoToCache()加words.size()<3检查
输入无行为变化
Influence:
PMS: BUG-383515
Summary by Sourcery
Harden device-manager input parsing and calculations against malformed and extreme fuzz-test inputs.
Bug Fixes:
Tests: