Skip to content

fix: add input validation to bad sector re-verify button - #236

Open
wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/agent/790f92ecd44e
Open

wangrong1069 wants to merge 1 commit into
linuxdeepin:masterfrom
wangrong1069:agent/agent/790f92ecd44e

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The "re-verify" button (onAgainVerifyButtonClicked()) in the bad sector verification dialog lacked the inputValueIsEffective() validation guard that onStartVerifyButtonClicked() already had. This allowed out-of-range timeout values (e.g. 1, when valid range is 100-3000) to proceed with re-verification. Additionally, checkNumber was read from stale QSettings cache (m_settings->value("SettingData/CheckNumber")) instead of the current UI input fields, causing re-verification to use outdated values.

Key evidence: diskbadsectorsdialog.cpp:640 (onStartVerifyButtonClicked has guard) vs diskbadsectorsdialog.cpp:1000 (onAgainVerifyButtonClicked lacked guard); inputValueIsEffective() at line 531 validates timeout range 100-3000.

修复方案

Added inputValueIsEffective() guard at the top of onAgainVerifyButtonClicked() (after the debug log, before any state changes), and replaced the QSettings cache read for checkNumber with a switch(m_methodComboBox->currentIndex()) that reads from m_checkTimesEdit or m_timeoutEdit — matching the existing pattern in onStartVerifyButtonClicked() exactly.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target function onAgainVerifyButtonClicked() was introduced in commit 34ed42a (2020-12-29) and never had input validation; this change does not revert any historical fix
  • Only two references exist: the header declaration (diskbadsectorsdialog.h:123, unchanged) and a unit test (ut_application.cpp:681, which sets timeout=300 within valid range, so the guard passes and behavior is unchanged)

Business Impact Scope

Affected module: Bad sector verification dialog in disk manager. The fix ensures the "re-verify" button validates user input (check times 1-16, timeout 100-3000) before proceeding, consistent with the "start verify" button. Users who enter out-of-range values and click "re-verify" will now be blocked instead of proceeding with invalid parameters.

Verification Suggestion

Regression test: verify that re-verify with valid timeout (e.g. 300) proceeds normally, and re-verify with out-of-range timeout (e.g. 1) is blocked. Also verify re-verify with out-of-range check times (e.g. 0 or 17) is blocked.


根因分析

坏道检测对话框中的"重新检测"按钮(onAgainVerifyButtonClicked())缺少 inputValueIsEffective() 校验守卫,而"开始检测"按钮(onStartVerifyButtonClicked())已有该校验。这导致超范围超时时间(如 1,有效范围为 100-3000)可通过重新检测。此外,checkNumber 从 QSettings 缓存读取而非当前 UI 输入字段,导致重新检测使用过期值。

关键证据:diskbadsectorsdialog.cpp:640(onStartVerifyButtonClicked 有守卫)对比 diskbadsectorsdialog.cpp:1000(onAgainVerifyButtonClicked 缺少守卫);inputValueIsEffective() 在第 531 行校验超时范围 100-3000。

修复方案

在 onAgainVerifyButtonClicked() 函数顶部添加 inputValueIsEffective() 守卫(在调试日志之后、任何状态变更之前),并将 checkNumber 的 QSettings 缓存读取替换为 switch(m_methodComboBox->currentIndex()) 从 m_checkTimesEdit 或 m_timeoutEdit 读取,与 onStartVerifyButtonClicked() 的既有模式完全一致。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标函数 onAgainVerifyButtonClicked() 在 commit 34ed42a(2020-12-29)引入以来从未有输入校验,本次改动不撤销任何历史修复
  • 仅有两处引用:头文件声明(diskbadsectorsdialog.h:123,未修改)和单元测试(ut_application.cpp:681,测试设置 timeout=300 在有效范围内,守卫通过,行为不变)

业务影响范围

受影响模块:磁盘管理器坏道检测对话框。修复确保"重新检测"按钮在执行前校验用户输入(检测次数 1-16,超时时间 100-3000),与"开始检测"按钮行为一致。用户输入超范围值后点击"重新检测"将被拦截。

验证建议

回归测试:验证重新检测时输入有效超时值(如 300)正常执行,输入超范围超时值(如 1)被拦截,输入超范围检测次数(如 0 或 17)被拦截。

PMS: BUG-350579

Summary by Sourcery

Validate re-verification inputs and apply the current dialog values when restarting bad-sector verification.

Bug Fixes:

  • Ensure bad-sector re-verification rejects invalid check-count and timeout inputs before starting.
  • Use the current verification settings from the dialog instead of stale cached values when re-verifying.

1. Root cause: onAgainVerifyButtonClicked() lacked inputValueIsEffective()
   guard, allowing out-of-range timeout values (e.g. 1, valid: 100-3000)
   to proceed with re-verification; it also read checkNumber from stale
   QSettings cache instead of current UI fields
2. Fix: add inputValueIsEffective() guard at function entry (matching
   onStartVerifyButtonClicked), and read checkNumber from UI fields via
   m_methodComboBox switch instead of QSettings cache
3. Impact: re-verify button now validates input same as start-verify;
   no signature change, existing unit test (timeout=300) still passes

Log: 坏道重新检测按钮增加输入校验,拦截超范围超时时间

Influence:
1. Test re-verify with valid timeout value (e.g. 300) proceeds normally
2. Test re-verify with out-of-range timeout (e.g. 1) is blocked
3. Test re-verify with out-of-range check times (e.g. 0 or 17) is blocked

fix: 坏道重新检测按钮增加输入校验

1. 根因:onAgainVerifyButtonClicked() 缺少 inputValueIsEffective() 校验守卫,
   超范围超时时间(如 1,有效范围 100-3000)可通过重新检测;同时从
   QSettings 缓存读取 checkNumber 而非当前 UI 字段
2. 方案:在函数入口添加 inputValueIsEffective() 守卫(与
   onStartVerifyButtonClicked 对齐),并通过 m_methodComboBox 开关
   从 UI 字段读取 checkNumber,不再使用 QSettings 缓存
3. 影响:重新检测按钮与首次检测按钮校验行为一致;无签名变更,
   既有单元测试(超时=300)不受影响

Log: 坏道重新检测按钮增加输入校验,拦截超范围超时时间

Influence:
1. 测试重新检测时输入有效超时值(如 300)正常执行
2. 测试重新检测时输入超范围超时值(如 1)被拦截
3. 测试重新检测时输入超范围检测次数(如 0 或 17)被拦截

PMS: BUG-350579
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wangrong1069

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

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The re-verify action now applies the same input validation as initial verification and derives its check count from the current UI selection, preventing invalid or stale parameters from being used.

Sequence diagram for validated bad-sector re-verification

sequenceDiagram
    actor User
    participant Dialog as DiskBadSectorsDialog
    participant Input as Current UI inputs
    participant Verify as Verification process

    User->>Dialog: onAgainVerifyButtonClicked()
    Dialog->>Dialog: inputValueIsEffective()
    alt invalid input
        Dialog-->>User: return
    else valid input
        Dialog->>Input: currentIndex()
        Dialog->>Input: text().toInt()
        Dialog->>Verify: start re-verification with current checkNumber
    end
Loading

File-Level Changes

Change Details Files
Validate re-verification inputs before changing dialog state or starting work.
  • Added an early return when inputValueIsEffective() fails.
  • Logged invalid input and preserved existing behavior for valid values.
application/widgets/diskbadsectorsdialog.cpp
Use current UI values for the re-verification count instead of stale persisted settings.
  • Selected check count from the active verification method.
  • Read count from the check-times or timeout edit control, with a default fallback.
application/widgets/diskbadsectorsdialog.cpp

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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 99 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为坏道重新校验按钮添加了输入验证,并根据校验方式从对应UI输入框获取checkNumber,逻辑正确、结构清晰、无安全漏洞。仅存在魔法数字8的轻微代码性能建议,整体代码质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无语法逻辑问题,代码保持良好。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无代码质量问题,代码保持良好。']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议将默认值8定义为命名常量,如 static const int kDefaultCheckNumber = 8;,提高代码可维护性。']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无安全问题,输入验证的添加是一个积极的安全改进。']


💡 改进建议代码示例

// 建议将魔法数字8定义为命名常量 // 在类定义或文件头部添加: static const int kDefaultCheckNumber = 8;
// 在 onAgainVerifyButtonClicked() 中使用: int checkNumber = kDefaultCheckNumber; switch (m_methodComboBox->currentIndex()) { case 0: {
    checkNumber = m_checkTimesEdit->text().toInt();
    break;
} case 1: {
    checkNumber = m_timeoutEdit->text().toInt();
    break;
} default:
    break;
}

本报告由 AI 代码审查工具自动生成

@deepin-bot

deepin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.28
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #251

@deepin-bot

deepin-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.29
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #259

@deepin-bot

deepin-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.30
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #261

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.

2 participants