Skip to content

Commit

Permalink
fix: Crash when not found libffmpegthumbnailer.so
Browse files Browse the repository at this point in the history
软件调整环境变量,可能未查找到库,解析接口时,
遗漏判空处理,导致访问越界;
同时调整创建临时图片的方式,改为 QTemporaryDir 的方式.

Log: 修复未查找到ffmpeg依赖包时崩溃的问题
Bug: https://pms.uniontech.com/bug-view-213565.html
Influence: MovieCover
  • Loading branch information
rb-union committed Sep 13, 2023
1 parent 155857a commit 601706a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions libimageviewer/movieservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QProcess>
#include <QtDebug>
#include <QJsonDocument>
#include <QTemporaryDir>
#include "unionimage/baseutils.h"
#include "service/ffmpegvideothumbnailer.h"

Expand Down Expand Up @@ -211,10 +212,15 @@ QImage MovieService::getMovieCover_ffmpegthumbnailer(const QUrl &url, const QStr
}

QString path = url.toLocalFile();
QString savePath;
QFileInfo info(path);

//QString savePath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QDir::separator() + info.fileName() + ".png");
QString savePath(bufferPath + info.fileName() + ".png");
QTemporaryDir tempDir;
// 此处临时文件创建后被删除,调整为使用tmp目录
if (tempDir.isValid()) {
savePath = tempDir.filePath(info.fileName() + ".png");
} else {
savePath = QString(bufferPath + info.fileName() + ".png");
}

QByteArray output;

Check warning on line 225 in libimageviewer/movieservice.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Unused variable: output
try {
Expand Down
7 changes: 7 additions & 0 deletions libimageviewer/service/ffmpegvideothumbnailer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QLibrary>
#include <QDir>
#include <QLibraryInfo>
#include <QDebug>

#include <libffmpegthumbnailer/videothumbnailerc.h>

Expand Down Expand Up @@ -38,6 +39,12 @@ bool initFFmpegVideoThumbnailer()
m_mvideo_thumbnailer_create_image_data = reinterpret_cast<mvideo_thumbnailer_create_image_data>(library.resolve("video_thumbnailer_create_image_data"));
m_mvideo_thumbnailer_destroy_image_data = reinterpret_cast<mvideo_thumbnailer_destroy_image_data>(library.resolve("video_thumbnailer_destroy_image_data"));
m_mvideo_thumbnailer_generate_thumbnail_to_buffer = reinterpret_cast<mvideo_thumbnailer_generate_thumbnail_to_buffer>(library.resolve("video_thumbnailer_generate_thumbnail_to_buffer"));

if (nullptr == m_creat_video_thumbnailer) {
qWarning() << QString("Resolve libffmpegthumbnailer.so data failed, %1").arg(library.errorString());
resolveSuccessed = false;
return false;
}
m_video_thumbnailer = m_creat_video_thumbnailer();

if (m_mvideo_thumbnailer_destroy == nullptr
Expand Down

0 comments on commit 601706a

Please sign in to comment.