Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion reader/app/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,13 @@
cleanedCount++;
qCDebug(appLog) << "Cleaned orphan state:" << path;
}
// 同步清理书签(在同一事务中保证数据一致性)
// 同步清理书签与标签页组(在同一事务中保证数据一致性)
deleteQuery.prepare("DELETE FROM bookmark WHERE filePath = :filePath");

Check warning on line 798 in reader/app/Database.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function deleteQuery.prepare() is not used.
deleteQuery.bindValue(":filePath", path);
deleteQuery.exec();

Check warning on line 800 in reader/app/Database.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function deleteQuery.exec() is not used.
deleteQuery.prepare("DELETE FROM tabgroup WHERE filePath = :filePath");

Check warning on line 801 in reader/app/Database.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function deleteQuery.prepare() is not used.
deleteQuery.bindValue(":filePath", path);
deleteQuery.exec();

Check warning on line 803 in reader/app/Database.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function deleteQuery.exec() is not used.
}
transaction.commit();

Expand Down
35 changes: 35 additions & 0 deletions reader/browser/BrowserPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@

const int ICON_SIZE = 23;

// 主线程专用的存活页注册表:入队时的 page 裸指针仅在回包时由主线程 handler 解引用,
// handler 必须先经 existPage 校验,避免向已析构页面回包(UAF)
static QSet<const BrowserPage *> g_alivePages;

BrowserPage::BrowserPage(SheetBrowser *parent, int index, DocSheet *sheet) :
QGraphicsItem(), m_sheet(sheet), m_parent(parent), m_index(index)
{
qCDebug(appLog) << "BrowserPage created, index:" << index;
g_alivePages.insert(this);
setAcceptHoverEvents(true);

setFlag(QGraphicsItem::ItemIsPanel);
Expand All @@ -48,7 +53,9 @@ BrowserPage::BrowserPage(SheetBrowser *parent, int index, DocSheet *sheet) :
BrowserPage::~BrowserPage()
{
// qCDebug(appLog) << "BrowserPage destroyed, index:" << m_index;
g_alivePages.remove(this);
PageRenderThread::clearImageTasks(m_sheet, this);
PageRenderThread::clearAllTasksForPage(this);

// 断开并销毁夜间异步任务 watcher:后台滤镜任务持有的都是副本,安全丢弃
delete m_nightWatcher;
Expand All @@ -62,6 +69,12 @@ BrowserPage::~BrowserPage()
// qCDebug(appLog) << "BrowserPage::~BrowserPage() - Destructor completed";
}

bool BrowserPage::existPage(const BrowserPage *page)
{
// 仅主线程调用:注册表只在主线程增删,无需加锁
return g_alivePages.contains(page);
}

QRectF BrowserPage::boundingRect() const
{
// qCDebug(appLog) << "BrowserPage::boundingRect() - Calculating bounding rectangle";
Expand Down Expand Up @@ -329,6 +342,10 @@ void BrowserPage::render(const double &scaleFactor, const Dr::Rotation &rotation

task.page = this;

task.renderer = m_sheet ? m_sheet->rendererPtr() : nullptr;
task.uuid = m_sheet ? m_sheet->uuid() : QString();
task.pageIndex = itemIndex();

task.pixmapId = m_pixmapId;

const qreal deviceRatio = dApp ? dApp->devicePixelRatio() : 1.0;
Expand All @@ -345,6 +362,12 @@ void BrowserPage::render(const double &scaleFactor, const Dr::Rotation &rotation

task.page = this;

task.renderer = m_sheet ? m_sheet->rendererPtr() : nullptr;
task.uuid = m_sheet ? m_sheet->uuid() : QString();
task.pageIndex = itemIndex();
task.scaleFactor = m_scaleFactor;
task.originSize = m_originSizeF;

task.pixmapId = m_pixmapId;

const qreal deviceRatio = dApp ? dApp->devicePixelRatio() : 1.0;
Expand All @@ -365,6 +388,10 @@ void BrowserPage::render(const double &scaleFactor, const Dr::Rotation &rotation

task.page = this;

task.renderer = m_sheet ? m_sheet->rendererPtr() : nullptr;
task.uuid = m_sheet ? m_sheet->uuid() : QString();
task.pageIndex = itemIndex();

PageRenderThread::appendTask(task);
}
}
Expand Down Expand Up @@ -394,6 +421,10 @@ void BrowserPage::renderRect(const QRectF &rect)

task.page = this;

task.renderer = m_sheet ? m_sheet->rendererPtr() : nullptr;
task.uuid = m_sheet ? m_sheet->uuid() : QString();
task.pageIndex = itemIndex();

task.pixmapId = m_pixmapId;

task.whole = QRect(0, 0,
Expand Down Expand Up @@ -651,6 +682,10 @@ void BrowserPage::loadWords()

task.page = this;

task.renderer = m_sheet ? m_sheet->rendererPtr() : nullptr;
task.uuid = m_sheet ? m_sheet->uuid() : QString();
task.pageIndex = itemIndex();

PageRenderThread::appendTask(task);

m_wordHasRendered = false;
Expand Down
9 changes: 9 additions & 0 deletions reader/browser/BrowserPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class BrowserPage : public QGraphicsItem

~BrowserPage() override;

/**
* @brief existPage
* 判断页面是否存活(仅主线程调用)。渲染回包 handler 解引用 task.page
* 之前必须校验,避免向已析构页面回包
* @param page 待校验页面
* @return 存活返回 true
*/
static bool existPage(const BrowserPage *page);

/**
* @brief 文档页缩放后的原区域 不受旋转影响
* @return
Expand Down
Loading
Loading