Skip to content

fix: fix 5 fuzz test security issues in devicemanager - #982

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
liyigang1:agent/bugfix/383515
Nov 24, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
liyigang1:agent/bugfix/383515

Conversation

@liyigang1

@liyigang1 liyigang1 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

fix: fix 5 fuzz test security issues in devicemanager

  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 16-char cap;
    validate double range before static_cast in convertToBytes(); add
    words.size()<3 guard in loadSgSmartCtlInfoToCache()
  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并限制16字符;convertToBytes()转换前校验
    数值范围;loadSgSmartCtlInfoToCache()加words.size()<3检查
  3. 影响:消除模糊测试输入下的除零、整数溢出、越界读取路径,对正常
    输入无行为变化

Influence:

  1. 测试零值/空分辨率字符串的屏幕比例计算
  2. 测试超长十六进制字符串的hexToDec转换
  3. 测试超大数值的convertToBytes转换
  4. 测试格式异常行的loadSgSmartCtlInfoToCache处理

PMS: BUG-383515

Summary by Sourcery

Harden device-manager input parsing and calculations against malformed and extreme fuzz-test inputs.

Bug Fixes:

  • Prevent divide-by-zero and invalid screen-ratio calculations for zero-valued resolutions.
  • Prevent numeric overflow and undefined conversions when parsing hexadecimal and storage-size values.
  • Ignore malformed storage-device entries that lack the expected fields instead of accessing out-of-range data.

Tests:

  • Update the load-information test metadata to reflect the current copyright period.

@liyigang1
liyigang1 marked this pull request as draft November 19, 2026 13:44
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Guard SMART-device parsing against malformed lines before accessing the third path component.

  • deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/threadpooltask.cpp L1, L255-258

Prevent display-ratio calculation from dividing by zero by rejecting zero dimensions and guarding the GCD base case.

  • deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp L545-548, L563-565

Check the scaled storage size is within the quint64 range before converting it.

  • deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp L18, L172-177

Widen hexadecimal accumulation and cap the processed input length to avoid signed overflow.

  • deepin-devicemanager/src/Tool/EDIDParser.cpp L492-497

Tests

Update the thread pool task test file’s SPDX copyright range.

  • test/deepin-devicemanager-server/src/LoadInfo/ut_ThreadPoolTask.cpp L1

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

}
diskBytesSize = static_cast<quint64>(diskSizeFloat * multiplier);
double result = diskSizeFloat * multiplier;
if (result < 0.0 || result > static_cast<double>(std::numeric_limits<quint64>::max())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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`.

Comment on lines +518 to +520
if (width == 0 || height == 0) {
qCDebug(appLog) << "Width or height is zero, skip ratio calculation";
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +494 to +497
if (len > 16) {
len = 16;
}
for (i = 0; i < len; i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@liyigang1
liyigang1 force-pushed the agent/bugfix/383515 branch 2 times, most recently from 1928656 to b6573f3 Compare November 23, 2026 04:05
@liyigang1
liyigang1 changed the base branch from master to develop/eagle November 23, 2026 04:06
@liyigang1
liyigang1 marked this pull request as ready for review November 23, 2026 07:12
@liyigang1
liyigang1 changed the base branch from develop/eagle to master November 24, 2026 02:02
@liyigang1
liyigang1 marked this pull request as draft November 24, 2026 02:02
@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 6.0.76
EXISTED: yes
DISTRIBUTION: unstable

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
@liyigang1
liyigang1 marked this pull request as ready for review November 24, 2026 02:38
@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@liyigang1

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit b20364f into linuxdeepin:master Nov 24, 2026
14 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants