From 10cc2d278c189b3181088b1ab6a21eacc1102377 Mon Sep 17 00:00:00 2001 From: zhouyuanyuan Date: Thu, 30 Jul 2026 18:09:52 +0800 Subject: [PATCH 1/2] Fix crash caused by dereferencing empty YUV frame format --- YUViewLib/src/video/yuv/videoHandlerYUV.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/YUViewLib/src/video/yuv/videoHandlerYUV.h b/YUViewLib/src/video/yuv/videoHandlerYUV.h index 22b2efee1..b6b6f694b 100644 --- a/YUViewLib/src/video/yuv/videoHandlerYUV.h +++ b/YUViewLib/src/video/yuv/videoHandlerYUV.h @@ -137,6 +137,8 @@ class videoHandlerYUV : public videoHandler virtual std::optional getFormatAsString() const override { const auto frameFormat = FrameHandler::getFormatAsString(); + if (!frameFormat) + return {}; return *frameFormat + ";YUV;" + this->srcPixelFormat.getName(); } virtual bool setFormatFromString(const std::string_view format) override; From 49e2ab9e07f66ecddff186c6c97d9d131709d9d9 Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Wed, 5 Aug 2026 23:02:59 +0200 Subject: [PATCH 2/2] Reformat and add tests for videoHandlerYUV --- YUViewLib/src/video/yuv/videoHandlerYUV.cpp | 8 + YUViewLib/src/video/yuv/videoHandlerYUV.h | 8 +- .../VideoHandlerRawTestDataLoader.cpp | 6 +- .../{rgb => }/VideoHandlerRawTestDataLoader.h | 4 +- .../video/rgb/videoHandlerRGBTest.cpp | 3 +- .../video/yuv/PixelFormatYUVHelper.cpp | 69 ++++++++ .../video/yuv/PixelFormatYUVHelper.h | 42 +++++ .../video/yuv/PixelFormatYUVTest.cpp | 40 +---- .../video/yuv/videoHandlerYUVTest.cpp | 162 ++++++++++++++++++ 9 files changed, 292 insertions(+), 50 deletions(-) rename YUViewUnitTest/video/{rgb => }/VideoHandlerRawTestDataLoader.cpp (97%) rename YUViewUnitTest/video/{rgb => }/VideoHandlerRawTestDataLoader.h (97%) create mode 100644 YUViewUnitTest/video/yuv/PixelFormatYUVHelper.cpp create mode 100644 YUViewUnitTest/video/yuv/PixelFormatYUVHelper.h create mode 100644 YUViewUnitTest/video/yuv/videoHandlerYUVTest.cpp diff --git a/YUViewLib/src/video/yuv/videoHandlerYUV.cpp b/YUViewLib/src/video/yuv/videoHandlerYUV.cpp index 013affa53..70b97437f 100644 --- a/YUViewLib/src/video/yuv/videoHandlerYUV.cpp +++ b/YUViewLib/src/video/yuv/videoHandlerYUV.cpp @@ -3151,6 +3151,14 @@ void videoHandlerYUV::setFormatFromCorrelation(const QByteArray &rawYUVData, int } } +std::optional videoHandlerYUV::getFormatAsString() const +{ + const auto frameFormat = FrameHandler::getFormatAsString(); + if (!frameFormat) + return {}; + return *frameFormat + ";YUV;" + this->srcPixelFormat.getName(); +} + bool videoHandlerYUV::setFormatFromString(const std::string_view format) { DEBUG_YUV("videoHandlerYUV::setFormatFromString " << format << "\n"); diff --git a/YUViewLib/src/video/yuv/videoHandlerYUV.h b/YUViewLib/src/video/yuv/videoHandlerYUV.h index b6b6f694b..d732c7f82 100644 --- a/YUViewLib/src/video/yuv/videoHandlerYUV.h +++ b/YUViewLib/src/video/yuv/videoHandlerYUV.h @@ -134,13 +134,7 @@ class videoHandlerYUV : public videoHandler virtual void setFormatFromCorrelation(const QByteArray &rawYUVData, int64_t fileSize = -1) override; - virtual std::optional getFormatAsString() const override - { - const auto frameFormat = FrameHandler::getFormatAsString(); - if (!frameFormat) - return {}; - return *frameFormat + ";YUV;" + this->srcPixelFormat.getName(); - } + virtual std::optional getFormatAsString() const override; virtual bool setFormatFromString(const std::string_view format) override; // Create the YUV controls and return a pointer to the layout. diff --git a/YUViewUnitTest/video/rgb/VideoHandlerRawTestDataLoader.cpp b/YUViewUnitTest/video/VideoHandlerRawTestDataLoader.cpp similarity index 97% rename from YUViewUnitTest/video/rgb/VideoHandlerRawTestDataLoader.cpp rename to YUViewUnitTest/video/VideoHandlerRawTestDataLoader.cpp index 80d26915c..c0442cc80 100644 --- a/YUViewUnitTest/video/rgb/VideoHandlerRawTestDataLoader.cpp +++ b/YUViewUnitTest/video/VideoHandlerRawTestDataLoader.cpp @@ -32,9 +32,9 @@ #include "VideoHandlerRawTestDataLoader.h" -#include