Skip to content

fix: The InstalledSize field can be empty#284

Merged
qiuzhiqian merged 1 commit into
masterfrom
fix-lastore-upgrade-query
Jan 13, 2026
Merged

fix: The InstalledSize field can be empty#284
qiuzhiqian merged 1 commit into
masterfrom
fix-lastore-upgrade-query

Conversation

@qiuzhiqian
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 13, 2026

CLA Assistant Lite bot:
提交邮箱中包含我们的合作伙伴,但您似乎并非合作伙伴的成员或对接人,请联系相关对接人将您添加至组织之中,或由其重新发起 Pull Request。
The commit email domain belongs to one of our partners, but it seems you are not yet a member of the current organization, please contact the contact person to add you to the organization or let them submit the Pull Request.

xml seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

以下是针对这段代码变更的详细审查意见:

1. 语法逻辑审查

变更内容
原代码:if (Size == 0 || InstalledSize == 0)
新代码:if (Size == 0)

问题分析

  • 这段修改移除了对 InstalledSize 的检查。
  • 逻辑上,原代码认为一个有效的升级包,其下载大小 (Size) 和安装后大小 (InstalledSize) 都不能为 0。
  • 新代码仅检查下载大小,不再校验安装大小。

潜在风险

  • 如果 InstalledSize 为 0 而被判定为有效包,可能会导致后续计算磁盘空间时出现除以 0 的错误,或者导致磁盘空间预估不准确。
  • 除非业务逻辑明确允许安装大小为 0 的包(例如元数据包、空壳包),否则这个修改可能引入逻辑漏洞。

2. 代码质量审查

改进建议

  1. 注释更新:代码上方的注释 // Check uint64_t fields - they should not be 0 在修改后不再准确,因为它声称检查所有 uint64_t 字段,但现在只检查了 Size

    • 建议修改注释为:// Check download size - it should not be 0
  2. 常量定义:直接使用 0 进行比较不够语义化。

    • 建议定义常量,例如 const uint64_t kInvalidSize = 0;,以提高可读性。

3. 代码性能审查

  • 这部分代码通常在包列表遍历或验证时调用,性能影响极小。
  • 修改前后性能差异可以忽略不计。

4. 代码安全审查

  • 逻辑漏洞:如前所述,移除 InstalledSize 检查可能导致无效包通过验证。
  • 建议:如果确实需要允许 InstalledSize 为 0,请确保:
    1. 所有使用 InstalledSize 的地方都处理了 0 的情况(例如除法运算)。
    2. 更新单元测试,覆盖 InstalledSize == 0 的场景。

5. 综合改进建议

如果业务确实需要允许 InstalledSize 为 0,建议按以下方式优化代码:

bool UpgradePackage::Valid() const {
    if (Name.empty() || Version.empty()) {
        return false;
    }
    
    // Check download size - it should not be 0
    if (Size == 0) {
        return false;
    }

    // Note: InstalledSize can be 0 for metadata packages
    return true;
}

或者,如果移除检查是错误的,应恢复原代码:

bool UpgradePackage::Valid() const {
    if (Name.empty() || Version.empty()) {
        return false;
    }
    
    // Check uint64_t fields - they should not be 0
    if (Size == 0 || InstalledSize == 0) {
        return false;
    }
    return true;
}

总结

这段修改需要谨慎评估:

  1. 如果业务逻辑确实允许 InstalledSize 为 0,那么修改是合理的,但需要更新注释和测试。
  2. 如果不允许 InstalledSize 为 0,那么这是一个错误的修改,应该恢复原代码。

建议与产品经理或相关业务方确认需求后再决定是否采纳此修改。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: electricface, qiuzhiqian

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

@qiuzhiqian qiuzhiqian merged commit 277d3a4 into master Jan 13, 2026
24 of 28 checks passed
@qiuzhiqian qiuzhiqian deleted the fix-lastore-upgrade-query branch January 13, 2026 12:57
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