Skip to content

fix: use SIGNAL/SLOT macro for sigYUVFrame connect - #513

Merged
lzwind merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-372435-use-signal-slot-macro-connect
Aug 7, 2026
Merged

fix: use SIGNAL/SLOT macro for sigYUVFrame connect#513
lzwind merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-372435-use-signal-slot-macro-connect

Conversation

@add-uos

@add-uos add-uos commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Replace new-style connect with old-style SIGNAL/SLOT macro syntax for sigYUVFrame signal connection to ensure compatibility.

将sigYUVFrame信号连接从新式函数指针语法改为旧式SIGNAL/SLOT宏语法以确保兼容性。

Log: 修改sigYUVFrame连接方式为SIGNAL/SLOT宏语法
PMS: BUG-372435
Influence: 仅影响YUV帧信号连接方式,功能行为不变。

Summary by Sourcery

Bug Fixes:

  • Resolve a compatibility issue by replacing the new-style function pointer connect for sigYUVFrame with the old-style SIGNAL/SLOT macro syntax.

Replace new-style connect with old-style SIGNAL/SLOT macro syntax
for sigYUVFrame signal connection to ensure compatibility.

将sigYUVFrame信号连接从新式函数指针语法改为旧式SIGNAL/SLOT宏语法以确保兼容性。

Log: 修改sigYUVFrame连接方式为SIGNAL/SLOT宏语法
PMS: BUG-372435
Influence: 仅影响YUV帧信号连接方式,功能行为不变。

@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 have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 7, 2026

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

Reviewer's Guide

Replaces a single new-style function-pointer Qt connect call for sigYUVFrame with the old-style SIGNAL/SLOT macro syntax to maintain compatibility, leaving behavior unchanged.

File-Level Changes

Change Details Files
Switch Qt connection for the YUV frame signal from new-style function-pointer syntax to old-style SIGNAL/SLOT macro syntax for compatibility with existing code/build environment.
  • Replaced the pointer-based connect for sigYUVFrame on MajorImageProcessingThread with a SIGNAL macro using the full parameter signature.
  • Replaced the pointer-based connect for slotShowYuv on PreviewOpenglWidget with a SLOT macro using the full parameter signature.
  • Kept the connection type as Qt::DirectConnection and preserved all other surrounding signal/slot connections.
src/src/videowidget.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

★ 总体评分:40分

■ 【总体评价】

代码试图通过强制直连优化YUV帧渲染性能,但引入了严重的跨线程OpenGL上下文冲突崩溃风险
逻辑存在严重错误且存在高危安全漏洞,触发评分上限强制降至40分

■ 【详细分析】

  • 1.语法逻辑(存在严重错误)✕

在 videowidget::delayInit() 函数中,将信号槽连接强制指定为 Qt::DirectConnection。由于发送者 m_imgPrcThread 处于图像处理线程,而接收者 m_openglwidget 属于 UI/OpenGL 渲染组件,直连会导致 slotShowYuv 槽函数在图像处理线程中直接执行。如果槽函数内部调用了 update() 或任何 OpenGL API,将直接违反 Qt 的 GUI 线程规则,导致未定义行为或程序崩溃。
潜在问题:OpenGL 上下文冲突导致程序崩溃;多线程并发访问 UI 组件引发竞态条件
建议:移除 Qt::DirectConnection 参数,恢复使用 Qt::AutoConnection 让 Qt 自动将调用安全地转发到目标线程;若需降低延迟,应重构数据传递机制而非破坏线程边界

  • 2.代码质量(存在严重问题)✕

代码将 C++11 新式连接语法退化为传统的 SIGNAL/SLOT 宏连接。根据上下文分析,此举目的是为了绕过编译期的严格参数类型检查(如 uint 与 unsigned int 的不匹配)。这种做法掩盖了接口定义不一致的真实缺陷,属于极差的编程实践。
潜在问题:隐藏的类型不匹配可能在运行时导致隐式转换错误或内存截断;字符串宏无法在编译期发现拼写错误
建议:统一 sigYUVFrame 信号和 slotShowYuv 槽的参数类型(如统一使用 unsigned int),修复接口定义后恢复使用 C++11 新式连接语法

  • 3.代码性能(高效)✓

从微观角度看,Qt::DirectConnection 确实消除了跨线程事件队列的拷贝、排队和唤醒开销,对于高频 YUV 数据传递在理论上报文延迟最低,达到了修改者降低渲染延迟的初衷。
建议:保持对性能的关注,但应通过更安全的方式实现,例如使用共享内存配合条件变量传递帧指针,而非破坏 Qt 的线程安全模型

  • 4.代码安全(存在1个安全漏洞)✕

漏洞对比统计:新增漏洞 1 个,减少漏洞 0 个,持平 0 个
总体风险描述:在 videowidget.cpp 的 delayInit() 函数中,由于强制使用直连破坏了线程隔离,异常的图像帧数据或高频调用可触发底层图形库的线程安全断言,造成本地拒绝服务

  • 安全漏洞1(高危):[拒绝服务] 在 [videowidget::delayInit()/videowidget.cpp] 中,[跨线程强制使用 Qt::DirectConnection 调用 OpenGL 组件的槽函数,若槽函数内包含 UI 刷新或 OpenGL 绘制指令,会触发 Qt 线程安全断言或底层 OpenGL 上下文冲突,导致应用程序崩溃,攻击者可通过发送特定格式或高频的图像帧触发此漏洞造成拒绝服务] ——非常重要

  • 建议:移除 Qt::DirectConnection 参数;若必须追求极致性能,应重构为在图像处理线程完成 YUV 到 RGB 的转换,仅通过信号传递已转换的 QImage 对象,或将 OpenGL 上下文迁移至图像处理线程

■ 【改进建议代码示例】

// 修复步骤1:统一头文件中的信号与槽参数类型,避免编译期报错
// 在 MajorImageProcessingThread.h 中:
// signals:
//     void sigYUVFrame(std::shared_ptr<uchar[]> data, unsigned int width, unsigned int height);
// 
// 在 PreviewOpenglWidget.h 中:
// public slots:
//     void slotShowYuv(std::shared_ptr<uchar[]> data, unsigned int width, unsigned int height);

void videowidget::delayInit()
{
    if (m_imgPrcThread) {
        connect(m_imgPrcThread, SIGNAL(SendMajorImageProcessing(QImage *, int)),
                this, SLOT(ReceiveMajorImage(QImage *, int)));
        connect(m_imgPrcThread, SIGNAL(sigRenderYuv(bool)), this, SLOT(ReceiveOpenGLstatus(bool)));
        
        // 修复步骤2:使用 C++11 新式语法进行编译期类型检查,使用默认的 AutoConnection 保证线程安全
        // 跨线程时 AutoConnection 会自动变为 QueuedConnection,将执行安全的投递到 UI 线程
        connect(m_imgPrcThread, &MajorImageProcessingThread::sigYUVFrame,
                m_openglwidget, &PreviewOpenglWidget::slotShowYuv);
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

@add-uos: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
github-pr-review-ci cc91b55 link true /test github-pr-review-ci

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@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

@lzwind
lzwind merged commit d1a28a9 into linuxdeepin:master Aug 7, 2026
18 of 20 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