Repository navigation
fix(tabbar): guard out-of-range index and division by zero in fuzz cases - #739
Conversation
- Add bounds check in Tabbar::updateTab() before writing m_tabPaths/m_tabTruePaths to fix CWE-787 out-of-bounds write - Guard the division by DTabBar::count() in Tabbar::tabSizeHint() with count() > 0 to fix CWE-369 divide-by-zero - Add bounds check in Tabbar::handleTabIsRemoved() before reading m_tabPaths.at() to fix CWE-125 out-of-bounds read - Validate index in ThemeListModel::data() before accessing m_themes to fix CWE-125 out-of-bounds read - Add fuzz regression tests for all four PMS BUG#383519 findings with valid-index positive controls 修复(tabbar): 修复模糊测试发现的越界索引与除零问题 - Tabbar::updateTab() 写入 m_tabPaths/m_tabTruePaths 前增加越界校验,修复 CWE-787 越界写 - Tabbar::tabSizeHint() 以 count() > 0 保护对 DTabBar::count() 的除法,修复 CWE-369 除零 - Tabbar::handleTabIsRemoved() 读取 m_tabPaths.at() 前增加越界校验,修复 CWE-125 越界读 - ThemeListModel::data() 访问 m_themes 前校验索引有效性,修复 CWE-125 越界读 - 新增覆盖 PMS BUG#383519 全部四个问题的模糊测试回归用例,并含合法索引正向对照 Log: 修复安全专项模糊测试发现的标签栏越界写、越界读与除零问题,并补充回归测试 Bug: https://pms.uniontech.com/bug-view-383519.html PMS: BUG-383519
Reviewer's GuideImplementationGuard Tabbar::updateTab() against invalid indices before updating tab data.
Avoid dividing by zero when Tabbar::tabSizeHint() has no tabs.
Guard Tabbar::handleTabIsRemoved() against invalid indices before reading the tab path.
Validate the model index and row bounds before ThemeListModel::data() accesses theme data.
TestsAdd regression tests for the four fuzz findings, including valid-index behavior checks.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/controls/tabbar.cpp" line_range="248-249" />
<code_context>
void Tabbar::updateTab(int index, const QString &filePath, const QString &tabName)
{
+ if (index < 0 || index >= m_tabPaths.count()) {
+ return;
+ }
+
</code_context>
<issue_to_address>
**Save-as paths diverge from tabs**
When a save-as update finds a registered wrapper but the old path has no matching tab index, `Tabbar::updateTab()` returns without changing the tab, while `Window::updateSaveAsFileName()` and `Window::updateSabeAsFileNameTemp()` continue updating the wrapper path and map key. The wrapper then points to the new path while the tab retains the old one.
Make the save-as callers stop updating the wrapper and map when the tab update cannot be performed.
</issue_to_address>
### Comment 2
<location path="tests/src/controls/ut_tabbar_fuzz383519.cpp" line_range="99" />
<code_context>
+ // 正向对照:走真实移除信号路径(removeTab -> tabIsRemoved -> handleTabIsRemoved)
+ tab->addTab("/tmp/fuzz383519.txt", "fuzz");
+ EXPECT_EQ(1, tab->count());
+ tab->removeTab(0);
+ EXPECT_EQ(0, tab->count());
+ EXPECT_TRUE(tab->m_tabPaths.isEmpty());
</code_context>
<issue_to_address>
**Valid removal control fails**
When the test runs its valid-index control using `removeTab(0)` without a `tabIsRemoved` emission, `handleTabIsRemoved_outOfRange` expects `m_tabPaths` to be empty after `tab->removeTab(0)`, but ordinary `removeTab` removes the displayed tab without emitting the custom `tabIsRemoved` signal connected to `handleTabIsRemoved`; the path remains and the test fails with the correct bounds check.
Exercise the actual `tabIsRemoved` signal path (or emit the signal directly) for the valid-index control.
</issue_to_address>
### Comment 3
<location path="tests/src/controls/ut_tabbar_fuzz383519.cpp" line_range="59-61" />
<code_context>
+ // 无效 QModelIndex(row == -1)
+ EXPECT_FALSE(model.data(QModelIndex(), ThemeListModel::ThemeName).isValid());
+ // row 越过尾部:QAbstractListModel::index() 对越界行返回无效索引
+ EXPECT_FALSE(model.data(model.index(rows, 0), ThemeListModel::ThemeName).isValid());
+ EXPECT_FALSE(model.data(model.index(rows + 3, 0), ThemeListModel::ThemePath).isValid());
+ EXPECT_FALSE(model.data(model.index(rows + 100000, 0), ThemeListModel::ThemeName).isValid());
+
+ // 正向对照:合法行返回主题名(环境未安装主题文件时跳过)
</code_context>
<issue_to_address>
**Model row bound is untested**
When the row-bound guard is later removed or weakened, `model.index(rows, 0)` and the larger-row variants are invalid indexes, so `data()` returns at `!index.isValid()` before the row-range check; the regression still passes if the `r >= m_themes.count()` guard is removed, leaving valid out-of-range rows untested.
Add a test that passes `data()` a valid `QModelIndex` whose row is outside `m_themes` and verifies that it returns an invalid `QVariant`.
</issue_to_address>| if (index < 0 || index >= m_tabPaths.count()) { | ||
| return; |
There was a problem hiding this comment.
🟡 Medium · Save-as paths diverge from tabs
When a save-as update finds a registered wrapper but the old path has no matching tab index, Tabbar::updateTab() returns without changing the tab, while Window::updateSaveAsFileName() and Window::updateSabeAsFileNameTemp() continue updating the wrapper path and map key. The wrapper then points to the new path while the tab retains the old one.
Make the save-as callers stop updating the wrapper and map when the tab update cannot be performed.
Prompt for AI agents
In `src/controls/tabbar.cpp` at lines 248-249:
**Save-as paths diverge from tabs**
When a save-as update finds a registered wrapper but the old path has no matching tab index, `Tabbar::updateTab()` returns without changing the tab, while `Window::updateSaveAsFileName()` and `Window::updateSabeAsFileNameTemp()` continue updating the wrapper path and map key. The wrapper then points to the new path while the tab retains the old one.
Make the save-as callers stop updating the wrapper and map when the tab update cannot be performed.| // 正向对照:走真实移除信号路径(removeTab -> tabIsRemoved -> handleTabIsRemoved) | ||
| tab->addTab("/tmp/fuzz383519.txt", "fuzz"); | ||
| EXPECT_EQ(1, tab->count()); | ||
| tab->removeTab(0); |
There was a problem hiding this comment.
🟡 Medium · Valid removal control fails
When the test runs its valid-index control using removeTab(0) without a tabIsRemoved emission, handleTabIsRemoved_outOfRange expects m_tabPaths to be empty after tab->removeTab(0), but ordinary removeTab removes the displayed tab without emitting the custom tabIsRemoved signal connected to handleTabIsRemoved; the path remains and the test fails with the correct bounds check.
Exercise the actual tabIsRemoved signal path (or emit the signal directly) for the valid-index control.
Prompt for AI agents
In `tests/src/controls/ut_tabbar_fuzz383519.cpp` at line 99:
**Valid removal control fails**
When the test runs its valid-index control using `removeTab(0)` without a `tabIsRemoved` emission, `handleTabIsRemoved_outOfRange` expects `m_tabPaths` to be empty after `tab->removeTab(0)`, but ordinary `removeTab` removes the displayed tab without emitting the custom `tabIsRemoved` signal connected to `handleTabIsRemoved`; the path remains and the test fails with the correct bounds check.
Exercise the actual `tabIsRemoved` signal path (or emit the signal directly) for the valid-index control.| EXPECT_FALSE(model.data(model.index(rows, 0), ThemeListModel::ThemeName).isValid()); | ||
| EXPECT_FALSE(model.data(model.index(rows + 3, 0), ThemeListModel::ThemePath).isValid()); | ||
| EXPECT_FALSE(model.data(model.index(rows + 100000, 0), ThemeListModel::ThemeName).isValid()); |
There was a problem hiding this comment.
🟡 Medium · Model row bound is untested
When the row-bound guard is later removed or weakened, model.index(rows, 0) and the larger-row variants are invalid indexes, so data() returns at !index.isValid() before the row-range check; the regression still passes if the r >= m_themes.count() guard is removed, leaving valid out-of-range rows untested.
Add a test that passes data() a valid QModelIndex whose row is outside m_themes and verifies that it returns an invalid QVariant.
Prompt for AI agents
In `tests/src/controls/ut_tabbar_fuzz383519.cpp` at lines 59-61:
**Model row bound is untested**
When the row-bound guard is later removed or weakened, `model.index(rows, 0)` and the larger-row variants are invalid indexes, so `data()` returns at `!index.isValid()` before the row-range check; the regression still passes if the `r >= m_themes.count()` guard is removed, leaving valid out-of-range rows untested.
Add a test that passes `data()` a valid `QModelIndex` whose row is outside `m_themes` and verifies that it returns an invalid `QVariant`.|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, pppanghu77 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
修复(tabbar): 修复模糊测试发现的越界索引与除零问题
Log: 修复安全专项模糊测试发现的标签栏越界写、越界读与除零问题,并补充回归测试
Bug: https://pms.uniontech.com/bug-view-383519.html
PMS: BUG-383519
改动内容 / Changes
验证 / Verification
Summary by Sourcery
Harden tab and theme model handling against invalid indexes and empty-state calculations.
Bug Fixes:
Tests: