From 30dddca58612a539941417dcae74d290e66805a9 Mon Sep 17 00:00:00 2001 From: liujinchang Date: Thu, 19 Nov 2026 15:48:43 +0800 Subject: [PATCH] fix(tabbar): guard out-of-range index in fuzz cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add bounds check in Tabbar::updateTab() before writing m_tabPaths/m_tabTruePaths to fix CWE-787 out-of-bounds write - Add bounds check in Tabbar::handleTabIsRemoved() before reading m_tabPaths.at() to fix CWE-125 out-of-bounds read 修复(tabbar): 修复模糊测试发现的越界索引问题 - Tabbar::updateTab() 写入 m_tabPaths/m_tabTruePaths 前增加越界校验,修复 CWE-787 越界写 - Tabbar::handleTabIsRemoved() 读取 m_tabPaths.at() 前增加越界校验,修复 CWE-125 越界读 Log: 修复安全专项模糊测试发现的标签栏越界写与越界读问题(data()/tabSizeHint() 两处已在先前提交中带防护) Bug: https://pms.uniontech.com/bug-view-383519.html PMS: BUG-383519 --- src/controls/tabbar.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/controls/tabbar.cpp b/src/controls/tabbar.cpp index c8c5b0b5..9d0f984e 100644 --- a/src/controls/tabbar.cpp +++ b/src/controls/tabbar.cpp @@ -314,6 +314,12 @@ void Tabbar::updateTab(int index, const QString &filePath, const QString &tabNam qCDebug(appLog) << "Updating tab index:" << index << "file:" << QFileInfo(filePath).fileName() << "new name:" << tabName; + + if (index < 0 || index >= m_tabPaths.count()) { + qCWarning(appLog) << "Invalid index for updateTab:" << index; + return; + } + // 适配助记符 '&' 后设置文本 setTabText(index, tabName); m_tabPaths[index] = filePath; @@ -984,6 +990,12 @@ void Tabbar::handleTabReleased(int index) void Tabbar::handleTabIsRemoved(int index) { qCDebug(appLog) << "Enter handleTabIsRemoved, index:" << index; + + if (index < 0 || index >= m_tabPaths.count()) { + qCWarning(appLog) << "Invalid index for handleTabIsRemoved:" << index; + return; + } + const QString filePath = m_tabPaths.at(index); Window *window = static_cast(this->window()); m_tabPaths.removeAt(index);