Skip to content

fix: 修复 GetNearestZones 空输入越界访问 (DDE-142) - #3444

Draft
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:fix/dde-142-getnearestzones-empty-guard
Draft

MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:fix/dde-142-getnearestzones-empty-guard

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

关联 issue

修复内容

GetNearestZonestotal_zones 为空时,循环不执行、nearest_zone_index 保持初值 -1,回退分支 zones.append(total_zones.at(-1)) 对空 QList 越界访问(未定义行为),可能导致 datetime 模块地图选时区功能在 zone 数据未加载时崩溃。

在函数入口增加 total_zones.isEmpty() 判空保护,空输入直接返回空列表:

ZoneInfoList zones;
if (total_zones.isEmpty()) {
  return zones;
}

调用方 datetimemodel.cpp 无需修改,无接口变更、无跨模块影响。

变更文件(仅 3 个)

  1. src/plugin-datetime/operation/timezoneMap/timezone_map_util.cppGetNearestZones 入口增加空输入判空保护(+3 行)
  2. tests/ut_timezone_map_util.cpp(新增)— 从 PR test: 补充控制中心 12 个核心单元的全量单元测试 (DDE-104) #3421 携带,并将原「空输入因 UB 故意省略」的 NOTE 替换为实际的 GetNearestZones.EmptyInputReturnsEmptyList 空输入测试用例
  3. tests/CMakeLists.txt — 注册 ut_timezone_map_util.cpp 及被测源 timezone_map_util.cpp,添加 include 目录(已剥离 gcov 插桩,仅保留最小测试注册)

与 PR #3421 的关系

本 PR 的 tests/ut_timezone_map_util.cpp#3421 对应文件的超集(新增了 GetNearestZones.EmptyInputReturnsEmptyList 空输入用例)。rebase #3421 时以本 PR 版本为准;#3421 可视情况关闭。

验证

阶段 结果
自测(单元测试) 16/16 通过(含新增空输入用例),被测源行覆盖率 97.4%、函数覆盖率 100%
代码审核 通过 ✅(3 次审核一致通过)
编译打包 deb 包构建成功,无编译错误无警告,Debian 规范检查通过
  • 基线分支/commit: master / 307bdbf
  • 新增用例 GetNearestZones.EmptyInputReturnsEmptyList 验证:空 total_zones 输入时函数返回空列表,不再触发 total_zones.at(-1) 越界访问。

Summary by Sourcery

Prevent crashes when timezone map data is unavailable and add regression coverage for timezone map utilities.

Bug Fixes:

  • Prevent GetNearestZones from accessing an empty zone list out of bounds by returning an empty result for empty input.

Enhancements:

  • Add unit coverage for timezone map coordinate conversions and nearest-zone selection behavior.

Build:

  • Register the timezone map utility source and tests with the unit-test target and add the required include path.

Tests:

  • Add comprehensive tests for coordinate conversion, threshold filtering, nearest-zone fallback, ordering, and empty-input handling.

1. Add isEmpty guard at GetNearestZones entry, return empty list early
2. Avoid out-of-bounds total_zones.at(-1) on empty input (UB)
3. Carry ut_timezone_map_util tests from PR linuxdeepin#3421 with empty-input case

Log: Prevent datetime timezone-map crash when no zone data is loaded

Influence:
1. Test clicking the timezone map with no zone data loaded
2. Verify GetNearestZones returns empty list for empty input
3. Run ut_timezone_map_util unit tests (16 cases)

fix: 修复 GetNearestZones 空输入越界访问

1. GetNearestZones 入口增加 total_zones 空输入判空保护,空输入直接返回空列表
2. 避免回退分支 total_zones.at(-1) 对空列表越界访问(未定义行为)
3. 携带 PR linuxdeepin#3421 的 ut_timezone_map_util 测试并补充空输入用例

Log: 避免 zone 数据未加载时点击时区地图导致控制中心崩溃

Influence:
1. 测试未加载 zone 数据时点击时区地图不崩溃
2. 验证 GetNearestZones 空输入返回空列表
3. 运行 ut_timezone_map_util 单元测试(16 个用例)
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MyLeeJiEun

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 Aug 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an entry-point guard to GetNearestZones so empty total_zones inputs return safely instead of dereferencing at(-1), with regression and broader utility tests wired into the existing unit-test target.

Sequence diagram for safe empty-zone lookup

sequenceDiagram
    participant Test as UnitTest
    participant Util as GetNearestZones
    participant Zones as total_zones

    Test->>Util: GetNearestZones(total_zones, threshold, x, y, map_width, map_height)
    Util->>Zones: isEmpty()
    alt empty input
        Util-->>Test: empty ZoneInfoList
    else zones available
        Util-->>Test: nearest zones
    end
Loading

File-Level Changes

Change Details Files
Prevent empty zone lists from reaching the nearest-zone fallback and add regression coverage for the boundary case.
  • Return an empty ZoneInfoList immediately when total_zones is empty.
  • Add a focused test proving empty input returns an empty result without out-of-bounds access.
  • Retain coverage for projection helpers and non-empty nearest-zone behavior, including fallback selection.
src/plugin-datetime/operation/timezoneMap/timezone_map_util.cpp
tests/ut_timezone_map_util.cpp
Integrate timezone map utility tests into the existing unit-test target.
  • Compile the new timezone utility test and implementation sources into the test executable.
  • Add the timezone map operation directory to the test include paths.
tests/CMakeLists.txt

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

@deepin-ci-robot

Copy link
Copy Markdown

Hi @MyLeeJiEun. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@deepin-bot

deepin-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.106
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3497

@deepin-bot

deepin-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.107
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3503

@deepin-bot

deepin-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.109
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3545

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants