Skip to content

fix: guard null sidebar pointer in setAlive close path - #396

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/ed025efde00c
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/ed025efde00c

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

fix: guard null sidebar pointer in setAlive close path

  1. Root cause: m_sidebar is initialized to nullptr and the same
    function already guards with "if (m_sidebar && ...)" at line
    1776, but the changeResetModelData() call at line 1800 omits
    the null check, causing a potential null pointer dereference
  2. Fix: add "if (m_sidebar)" guard before calling
    changeResetModelData() to skip the call when sidebar is null
  3. Impact: no behavior change when sidebar is non-null; prevents
    crash when sidebar pointer is null during document close path

Influence:

  1. Test opening and closing documents with sidebar visible
  2. Test closing documents when sidebar is not initialized
  3. Verify no regression on annotation save and bookmark persistence

fix: 修复关闭文档路径中侧边栏空指针解引用

  1. 根因:m_sidebar 初始化为 nullptr,同函数第 1776 行已有
    "if (m_sidebar && ...)" 守卫,但第 1800 行调用
    changeResetModelData() 时遗漏空检查,存在空指针解引用风险
  2. 方案:在调用 changeResetModelData() 前增加 "if (m_sidebar)"
    守卫,指针为空时跳过调用
  3. 影响:侧边栏非空时行为不变;侧边栏为空时避免崩溃

Influence:

  1. 测试侧边栏可见时打开和关闭文档
  2. 测试侧边栏未初始化时关闭文档
  3. 验证批注保存和书签持久化无回归

PMS: BUG-213

Summary by Sourcery

Bug Fixes:

  • Prevent a crash during document close when the sidebar is not initialized by safely skipping sidebar model reset.

1. Root cause: m_sidebar is initialized to nullptr and the same
   function already guards with "if (m_sidebar && ...)" at line
   1776, but the changeResetModelData() call at line 1800 omits
   the null check, causing a potential null pointer dereference
2. Fix: add "if (m_sidebar)" guard before calling
   changeResetModelData() to skip the call when sidebar is null
3. Impact: no behavior change when sidebar is non-null; prevents
   crash when sidebar pointer is null during document close path

Influence:
1. Test opening and closing documents with sidebar visible
2. Test closing documents when sidebar is not initialized
3. Verify no regression on annotation save and bookmark persistence

fix: 修复关闭文档路径中侧边栏空指针解引用

1. 根因:m_sidebar 初始化为 nullptr,同函数第 1776 行已有
   "if (m_sidebar && ...)" 守卫,但第 1800 行调用
   changeResetModelData() 时遗漏空检查,存在空指针解引用风险
2. 方案:在调用 changeResetModelData() 前增加 "if (m_sidebar)"
   守卫,指针为空时跳过调用
3. 影响:侧边栏非空时行为不变;侧边栏为空时避免崩溃

Influence:
1. 测试侧边栏可见时打开和关闭文档
2. 测试侧边栏未初始化时关闭文档
3. 验证批注保存和书签持久化无回归

PMS: BUG-213

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

Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 17 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

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 Sep 18, 2026

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

Reviewer's Guide

Adds a null guard around the sidebar reset-model update in DocSheet::setAlive(bool) so closing a document without an initialized sidebar no longer risks a crash, while retaining existing behavior and persistence flows when the sidebar exists.

Sequence diagram for guarded document close persistence

sequenceDiagram
    participant DocSheet
    participant Renderer
    participant Sidebar
    participant Database

    DocSheet->>Renderer: save()
    Renderer-->>DocSheet: success
    alt sidebar exists
        DocSheet->>Sidebar: changeResetModelData()
    end
    DocSheet->>Database: saveBookmarks(filePath(), m_bookmarks)
Loading

File-Level Changes

Change Details Files
Guard the sidebar-dependent reset-model update during document close/save handling.
  • Wrap the changeResetModelData() call in an m_sidebar null check.
  • Preserve existing behavior when the sidebar is initialized while preventing null-pointer dereference otherwise.
  • Keep annotation save state updates and bookmark persistence after the guarded call unchanged.
reader/uiframe/DocSheet.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

AI 代码审查报告

项目: linuxdeepin/deepin-reader
PR: #396
提交: fix: guard null sidebar pointer in setAlive close path
作者: pengfeixx
审查时间: 2026-09-18


总体评价

维度 评分 状态
语法逻辑 25/25
代码质量 25/25
代码性能 20/20
代码安全 30/30
总分 100/100 优秀

总体评价结论: 代码审查通过

本次提交修复了 DocSheet::setAlive() 函数关闭文档路径中的空指针解引用风险。在同函数第 1776 行已存在 m_sidebar 空指针守卫,但第 1800 行调用 changeResetModelData() 时遗漏了空检查。本次修复在调用前增加 if (m_sidebar) 守卫,与既有代码模式一致,修复正确且最小化。未发现安全问题。


维度1:语法逻辑(25/25)✓

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

分析

  1. 修改位于 DocSheet::setAlive(bool alive) 函数的 else 分支(即 alive=false,关闭文档路径),第 1797-1809 行
  2. 原代码在第 1800 行直接调用 m_sidebar->changeResetModelData(),未检查 m_sidebar 是否为空
  3. 同函数第 1776 行已有 if (m_sidebar && m_sidebar->isVisible()) 守卫,证明 m_sidebar 确实可能为 nullptr
  4. 修复在调用前增加 if (m_sidebar) 判断,逻辑正确,与既有模式一致
  5. 无编译错误,无逻辑缺陷,边界处理完善

维度2:代码质量(25/25)✓

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

分析

  1. 注释完整性: 修改区域保留了原有注释(第 1803-1804 行关于书签刷新内容指纹的说明),上下文注释充分
  2. 代码重复: 无重复代码,修复仅增加 3 行
  3. 结构合理性: 修改风格与同函数其他空指针守卫(第 1771、1776、1782、1787、1792 行)完全一致,使用大括号包裹的单行 if 语句
  4. 调试信息清理: 无残留调试代码

维度3:代码性能(20/20)✓

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

分析

  1. 空指针检查仅增加一次指针比较,开销可忽略
  2. m_sidebar 为空时跳过 changeResetModelData() 调用,实际减少了不必要的函数调用
  3. 无性能瓶颈,无不必要的资源分配

维度4:代码安全(30/30)✓

评价: 存在0个安全漏洞

分析

  1. 本次修改不涉及用户输入处理,无注入风险
  2. 无硬编码密钥、无敏感信息泄露
  3. 修复的空指针解引用属于稳定性问题而非安全漏洞
  4. 无缓冲区操作,无路径遍历风险

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个


修改文件清单

文件 修改类型 行数变化
reader/uiframe/DocSheet.cpp 修改 +3/-1

修改详情

文件: reader/uiframe/DocSheet.cpp
函数: DocSheet::setAlive(bool alive)
行号: 1800-1802

// 修改前:
m_sidebar->changeResetModelData();

// 修改后:
if (m_sidebar) {
    m_sidebar->changeResetModelData();
}

根因分析: m_sidebar 成员变量初始化为 nullptr,在某些使用场景下可能未被初始化。同函数第 1776 行已有空指针守卫,但第 1800 行遗漏了检查,导致关闭文档时可能发生空指针解引用崩溃。

修复方案: 在调用 changeResetModelData() 前增加 if (m_sidebar) 守卫,指针为空时跳过调用。修复正确,与既有代码模式一致。


审查结论

本次提交是一个精确的空指针解引用修复,代码变更最小化,与同函数已有的防御性编程模式一致。commit message 清晰描述了根因、修复方案和影响范围。代码审查通过,无安全问题,无性能问题,无质量问题。

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