Skip to content

fix: replace function-static pinch state and mechanical-safe Qt6 deprecated APIs - #417

Merged
deepin-bot[bot] merged 3 commits into
linuxdeepin:masterfrom
add-uos:fix/ut-scan-20261010
Oct 14, 2026
Merged

deepin-bot[bot] merged 3 commits into
linuxdeepin:masterfrom
add-uos:fix/ut-scan-20261010

Conversation

@add-uos

@add-uos add-uos commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

概述

本 PR 由单元测试/PMS 扫描缺陷甄别流程发现,对 13 条「单元测试/PMS 扫描发现的源码缺陷/静态分析发现」逐条甄别核对后,修复确认的问题并驳回误报/上游已修复项。

修复项(确认)

# 文件:行 问题 修法
1 reader/browser/SheetBrowser.cpp:946(pinchTriggered) canRotate/currentStepScaleFactor/tempScalefactor 为函数级 static,跨调用累计、多窗口共享互相污染;手势被打断(无 GestureFinished)后 static 残留导致下次捏合基线错误(BUG44491 捏合过于灵敏的深层根因) 改为 SheetBrowser 成员变量,GestureStarted 重置缩放基线,GestureFinished 清理,并补上 GestureCanceled 清理路径
2 3rdparty/deepin-pdfium/include/dpdfdoc.h:82 / dpdfpage.h:17 DPdfDoc::page() 返回的 DPdfPage* 由文档 m_pages 缓存持有(~DPdfDocPrivate qDeleteAll),调用方 delete 即 double-free,头文件未声明所有权契约 在两个头文件注释中声明所有权契约(所有权归文档,调用方不得 delete)。注:3rdparty/deepin-pdfium 为普通目录(非 git submodule),可直接修改
12 reader/Application.cpp:25/106、reader/MainWindow.cpp:240/244/595、reader/document/XpsDocumentAdapter.cpp:279、reader/widgets/SecurityDialog.cpp:38/42、reader/widgets/TransparentTextEdit.cpp:58 Qt6 过时 API(clang-diagnostic-deprecated-declarations)共 9 处机械安全修复 AA_UseHighDpiPixmaps 加 Qt5-only 守卫(Qt6 无效果);isTopLevel→isWindow(等价);QHoverEvent::pos()→position().toPoint()(Qt6 分支,Qt5 保持 pos());QLibraryInfo::location()→path()(沿用 Model.cpp 既有守卫模式);fromSecsSinceEpoch 改传 QTimeZone::UTC(行为等价,Qt6.5+ 分支);QString::count()→size()(3 处)

评估后暂缓(不改动,注明原因)

  • Application.cpp:97 QMouseEvent 废弃构造函数:新构造函数需显式传入 globalPos;此处 pos 由输入法光标矩形合成、并非真实全局坐标,右键菜单弹出位置依赖 globalPosition 语义,改动存在行为风险,评估后暂缓。
  • fontChanged 信号连接 4 处(CatalogTreeView.cpp:135 / RestoreTipWidget.cpp:38 / PagingWidget.cpp:94 / ScaleWidget.cpp:47):替换为 QEvent::ApplicationFontChange 需将 connect 改为事件过滤器/changeEvent 结构,属结构性改动,评估后暂缓。

驳回项(误报/上游已修复,不改代码)

# 原发现 驳回理由
3 reader/uiframe/CentralNavPage.cpp:29 kFormatsWithoutXps 死存储 当前 master 已由上游 commit cb6c64d 重构为 QStringList formats 条件追加,死存储已不存在
4 reader/load_libs.c:123 strcpy 不安全调用 当前 master 已由上游 commit 8721086 将 strcpy 替换为 malloc+memcpy(带长度),文件中已无 strcpy
5 reader/browser/BrowserPage.cpp:1029 空指针调用 按扫描基线核对为 removeAllAnnotation 中 annota->boundary() 空解引用,上游 commit 122ea00 已将守卫重排为先判空(当前 master :1034)
6 reader/browser/SheetBrowser.cpp:867 空指针调用 按扫描基线核对为 event()->type() 未判空,上游 commit 122ea00 已加 event 判空守卫(当前 master :925)
7-11 reader/browser/PageRenderThread.cpp:920/932/943/955/966 五处空指针调用 按扫描基线核对为五个 render 回调槽中 task.page 空时守卫穿透(guard 用 !=+&& 只拦非空但已析构),上游 commit 2713c9e 已将守卫改为 nullptr == task.page || !existPage(null 即返回),五处全部覆盖
13 与 12 同源合并统计 无独立条目

验证

  • 编译验证:Qt6 Debug(build-ut)下 deepin-pdfium-reader 与 deepin-reader 两个 target 均编译通过,无错误;已修复站点的废弃声明警告全部消除。
  • 未改动 tests/ 测试文件;未混入其他分支提交。

Log: 甄别 13 条扫描缺陷:修复捏合手势 static 状态泄漏、page 所有权契约说明与 9 处 Qt6 废弃 API,驳回 6 条已修复/误报项
Influence: 修复多窗口捏合互相污染与手势打断后缩放过灵敏(BUG44491 深层根因);消除 Qt6 废弃 API 警告;行为均为等价替换

Summary by Sourcery

Eliminate persistent pinch-state contamination, clarify PDF page ownership, and maintain Qt6 compatibility by removing deprecated API usage.

Bug Fixes:

  • Prevent pinch-gesture state from leaking across gestures or SheetBrowser instances, including interrupted and canceled gestures, which fixes overly sensitive scaling and cross-window interference.

Enhancements:

  • Document that DPdfPage objects are owned and released by DPdfDoc and must not be deleted by callers.
  • Replace affected Qt6-deprecated APIs with version-compatible equivalents while preserving Qt5 support and existing behavior.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

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 5 days and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes pinch gesture state leakage by making state instance-owned and resetting it across gesture lifecycles, documents DPdfPage ownership, and removes selected Qt6 deprecation warnings through guarded or equivalent API substitutions; packaging metadata is also updated.

Sequence diagram for isolated pinch gesture lifecycle

sequenceDiagram
    participant Gesture as QPinchGesture
    participant BrowserA as SheetBrowser instance A
    participant BrowserB as SheetBrowser instance B
    participant Sheet as Sheet

    Gesture->>BrowserA: pinchTriggered(gesture)
    BrowserA->>BrowserA: GestureStarted resets m_currentStepScaleFactor
    BrowserA->>BrowserA: Store m_tempScalefactor and m_canRotate
    Gesture->>BrowserA: ScaleFactorChanged
    BrowserA->>Sheet: setScaleFactor(curscalfactor)
    Gesture->>BrowserA: GestureCanceled
    BrowserA->>BrowserA: Clear pinch state
    Gesture->>BrowserB: pinchTriggered(gesture)
    BrowserB->>BrowserB: Uses instance-owned pinch state
    BrowserB->>Sheet: setScaleFactor(curscalfactor)
Loading

Flow diagram for guarded Qt6 API compatibility

flowchart LR
    Start["Qt-dependent API call"] --> Version{"Qt version"}
    Version -->|"Qt5"| Qt5["Use Qt5 API"]
    Version -->|"Qt6"| Qt6["Use Qt6 replacement"]
    Qt5 --> Equivalent["Equivalent application behavior"]
    Qt6 --> Equivalent
Loading

File-Level Changes

Change Details Files
Replaced function-static pinch gesture state with per-SheetBrowser state and explicit lifecycle resets.
  • Moved rotation and scale baseline variables into SheetBrowser members.
  • Reset the scale baseline on gesture start to prevent interrupted gestures from contaminating later gestures.
  • Cleared rotation, scale, and pinch UI state on both finished and canceled gestures.
reader/browser/SheetBrowser.cpp
reader/browser/SheetBrowser.h
Documented DPdfPage pointer ownership to prevent callers from incorrectly freeing document-managed pages.
  • Documented that DPdfDoc::page() returns a cached page owned and released by DPdfDoc.
  • Added the same ownership and double-free warning to the DPdfPage class documentation.
3rdparty/deepin-pdfium/include/dpdfdoc.h
3rdparty/deepin-pdfium/include/dpdfpage.h
Applied Qt-version-guarded, behavior-preserving replacements for selected deprecated Qt APIs.
  • Guarded the Qt5-only high-DPI attribute and selected Qt6 API branches for hover coordinates, library paths, and UTC time conversion.
  • Replaced equivalent QString count calls with size and QWidget isTopLevel with isWindow.
reader/Application.cpp
reader/MainWindow.cpp
reader/document/XpsDocumentAdapter.cpp
reader/widgets/SecurityDialog.cpp
reader/widgets/TransparentTextEdit.cpp
Updated application packaging metadata.
  • Bumped the Linglong package version from 6.6.1.1 to 6.6.2.1.
  • Added the corresponding Debian changelog entry.
linglong.yaml
debian/changelog

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

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 6.6.2
EXISTED: no
DISTRIBUTION: unstable

The pinch gesture state (canRotate, currentStepScaleFactor,
tempScalefactor) in SheetBrowser::pinchTriggered lived in function-level
statics: they leaked across SheetBrowser instances (multi-window
pollution), survived across unit-test runs, and left a stale scale
baseline behind when a gesture was interrupted without GestureFinished,
making the next pinch jump (too-sensitive scaling, BUG44491 deep cause).

Move them to SheetBrowser members, reset the scale baseline on
GestureStarted, and also clean up on GestureCanceled.

Log: 捏合手势状态由函数级 static 改为成员变量,手势开始时重置缩放基线,取消时同样清理
Influence: 修复多窗口捏合互相污染与手势打断后下次捏合缩放过灵敏的问题(BUG44491 深层根因)
DPdfDoc::page() caches the returned DPdfPage in the document (freed by
qDeleteAll in ~DPdfDocPrivate), so deleting it from the caller side is
a double-free. Declare the ownership contract in dpdfdoc.h page() and
the DPdfPage class docs in dpdfpage.h.

Log: 在 dpdfdoc.h/dpdfpage.h 注释中声明 DPdfDoc::page 返回指针的所有权契约
Influence: 仅文档注释变更,提示调用方不得 delete page() 返回的 DPdfPage,避免双重释放
@add-uos
add-uos force-pushed the fix/ut-scan-20261010 branch from ccc1c79 to fe2437b Compare October 10, 2026 05:22
- Application.cpp: guard AA_UseHighDpiPixmaps with Qt5-only check (no
  effect in Qt6) and replace deprecated isTopLevel() with isWindow()
- MainWindow.cpp: replace deprecated QHoverEvent::pos() with
  position().toPoint() (Qt6 branch) and QLibraryInfo::location() with
  path() (same pattern as Model.cpp)
- XpsDocumentAdapter.cpp: pass QTimeZone::UTC to fromSecsSinceEpoch
  instead of the deprecated Qt::UTC overload (behavior equivalent)
- SecurityDialog.cpp / TransparentTextEdit.cpp: replace deprecated
  QString::count() with size()

Deferred (structural, behavior-sensitive): QMouseEvent deprecated
constructor in Application.cpp (new ctor needs a global position the
synthesized cursor point cannot provide); the 4 fontChanged connects in
CatalogTreeView/RestoreTipWidget/PagingWidget/ScaleWidget (replacing
the signal with QEvent::ApplicationFontChange handling restructures
event processing).

Log: 替换机械安全的 Qt6 废弃 API:AA_UseHighDpiPixmaps/isTopLevel/pos/location/fromSecsSinceEpoch/count
Influence: 消除 9 处 Qt6 废弃 API 警告,行为不变(等价替换);fontChanged 4 处与 QMouseEvent 构造评估后暂缓
@add-uos
add-uos force-pushed the fix/ut-scan-20261010 branch from e217c38 to e408891 Compare October 10, 2026 05:35
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@add-uos

add-uos commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit d896442 into linuxdeepin:master Oct 14, 2026
8 of 9 checks passed
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