Skip to content

fix: walk the parent chain safely in CentralDocPage - #412

Open
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix/docpage-parent-chain
Open

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:fix/docpage-parent-chain

Conversation

@add-uos

@add-uos add-uos commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

问题

CentralDocPage 的 isFullScreen()/openFullScreen()/quitFullScreen()/onSheetCountChanged()(reader/uiframe/CentralDocPage.cpp :897/:908/:928/:976)均使用 parentWidget()->parentWidget()->parentWidget() 三级父链。parentWidget() 非虚且内部解引用 d 指针,任一级为空(嵌入场景/测试环境父链不足三级)即对空指针调用崩溃——末尾的 if (nullptr == mainWindow) 只能拦截第三级为空的情况。gdb 实测:setSidebarVisible(issue 164325 修复路径)触发 SIGSEGV at QWidget::parentWidget(this=0x0)。同文件 :976 的调用点之后用了 mainWindow && ... 判空,说明防护模式已知但未一致应用。

修复

新增文件内静态辅助 parentMainWindow(CentralDocPage *):逐级向上取父并随时判空,最后再做 dynamic_cast;4 处调用点统一替换。

背景

该问题由 AI 辅助单测(PMS 缺陷热点回归,BUG164325 用例运行时 gdb 定位)发现。

Summary by Sourcery

Safely traverse CentralDocPage’s parent hierarchy before accessing the parent MainWindow.

Bug Fixes:

  • Prevent crashes when CentralDocPage is embedded in a hierarchy with fewer than three parent widgets by safely resolving its parent MainWindow.
  • Apply consistent null-safe parent-window handling to fullscreen and sheet-count updates.

isFullScreen()/openFullScreen()/quitFullScreen()/onSheetCountChanged()
called parentWidget()->parentWidget()->parentWidget() unchecked; if the
widget has fewer than three levels of parents (embedded use, tests) the
chain dereferences a null QWidget and crashes. The existing null check
only covered the final dynamic_cast result. Replace the chained calls
with a parentMainWindow() helper that stops at the first null level.

Log:
Influence: doc page fullscreen handling

@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 @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 22 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: add-uos

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 30, 2026

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

Reviewer's Guide

CentralDocPage now resolves its owning MainWindow through a null-safe helper, preventing crashes when embedded or test widget hierarchies do not contain the expected three parent levels. All four affected call sites use the shared lookup.

Sequence diagram for null-safe MainWindow lookup

sequenceDiagram
    participant Caller
    participant CentralDocPage
    participant parentMainWindow
    participant QWidget
    participant MainWindow

    Caller->>CentralDocPage: isFullScreen()
    CentralDocPage->>parentMainWindow: parentMainWindow(this)
    loop Up to 3 levels while widget != nullptr
        parentMainWindow->>QWidget: parentWidget()
        QWidget-->>parentMainWindow: parent widget or nullptr
    end
    alt MainWindow found
        parentMainWindow->>MainWindow: isFullScreen()
        MainWindow-->>CentralDocPage: fullscreen state
    else Parent chain ends early or type mismatch
        parentMainWindow-->>CentralDocPage: nullptr
        CentralDocPage-->>Caller: false or return
    end
Loading

File-Level Changes

Change Details Files
Added a centralized, null-safe helper for resolving the owning MainWindow through the expected three-level widget parent chain.
  • Walk up to three parents while checking for null at every level.
  • Perform the MainWindow dynamic cast only after completing a safe traversal.
  • Return nullptr when the chain is incomplete or the target is not a MainWindow.
reader/uiframe/CentralDocPage.cpp
Applied the safe parent-chain lookup across all CentralDocPage fullscreen and sheet-count handling paths.
  • Replaced direct three-level parent dereferences in fullscreen status, entry, and exit methods.
  • Replaced the lookup in sheet-count change handling while retaining existing null-aware behavior.
reader/uiframe/CentralDocPage.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

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