From e872b6e88a87a3de8303f5c35c6b753ab11f918a Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Fri, 7 Aug 2026 18:07:54 +0200 Subject: [PATCH 1/4] Adopt some of the suggested changes. A max dimension is a good idea. --- YUViewLib/src/common/Typedef.h | 13 ++++++++++--- .../src/dataSource/DataSourceLocalFile.cpp | 2 +- YUViewLib/src/filesource/FileSource.cpp | 18 +++++++++++++++--- YUViewLib/src/filesource/FileSource.h | 10 +++++----- .../src/playlistitem/playlistItemRawFile.cpp | 7 ++++++- YUViewLib/src/video/FrameHandler.cpp | 4 ++-- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/YUViewLib/src/common/Typedef.h b/YUViewLib/src/common/Typedef.h index 155e6f11d..6c2a3a0bf 100644 --- a/YUViewLib/src/common/Typedef.h +++ b/YUViewLib/src/common/Typedef.h @@ -184,6 +184,8 @@ struct Ratio struct Size { + static constexpr unsigned MAX_DIMENSION = 100000; + constexpr Size(unsigned width, unsigned height) : width(width), height(height) {} constexpr Size() = default; @@ -196,9 +198,14 @@ struct Size return this->width != other.width || this->height != other.height; } explicit operator bool() const { return this->isValid(); } - constexpr bool isValid() const { return this->width > 0 && this->height > 0; } - unsigned width{}; - unsigned height{}; + constexpr bool isValid() const + { + return this->width > 0 && this->width < MAX_DIMENSION && // + this->height > 0 && this->height < MAX_DIMENSION; + } + + unsigned width{}; + unsigned height{}; }; struct Offset diff --git a/YUViewLib/src/dataSource/DataSourceLocalFile.cpp b/YUViewLib/src/dataSource/DataSourceLocalFile.cpp index 34becf6a1..f89370dfd 100644 --- a/YUViewLib/src/dataSource/DataSourceLocalFile.cpp +++ b/YUViewLib/src/dataSource/DataSourceLocalFile.cpp @@ -49,7 +49,7 @@ getLastWriteTime(const std::filesystem::path &filePath) noexcept { return {std::filesystem::last_write_time(filePath)}; } - catch (const std::exception &e) + catch (const std::exception &) { return {}; } diff --git a/YUViewLib/src/filesource/FileSource.cpp b/YUViewLib/src/filesource/FileSource.cpp index e5df613a9..68f82ccab 100644 --- a/YUViewLib/src/filesource/FileSource.cpp +++ b/YUViewLib/src/filesource/FileSource.cpp @@ -83,8 +83,20 @@ int64_t FileSource::readBytes(QByteArray &targetBuffer, int64_t startPos, int64_ if (!this->isOk()) return 0; + if (startPos < 0 || nrBytes <= 0) + return 0; + if (targetBuffer.size() < nrBytes) - targetBuffer.resize(nrBytes); + { + try + { + targetBuffer.resize(nrBytes); + } + catch (const std::bad_alloc &) + { + return 0; + } + } #if FILESOURCE_DEBUG_SIMULATESLOWLOADING && !NDEBUG QThread::msleep(50); @@ -133,7 +145,7 @@ std::optional FileSource::getFileSize() const const auto size = std::filesystem::file_size(this->fullFilePath); return static_cast(size); } - catch (const std::filesystem::filesystem_error &e) + catch (const std::filesystem::filesystem_error &) { return {}; } @@ -177,7 +189,7 @@ void FileSource::clearFileCache() LPCWSTR file = this->fullFilePath.wstring().c_str(); HANDLE hFile = - CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); + CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); CloseHandle(hFile); this->srcFile.setFileName(this->fullFilePath); diff --git a/YUViewLib/src/filesource/FileSource.h b/YUViewLib/src/filesource/FileSource.h index c9b89875d..389b19564 100644 --- a/YUViewLib/src/filesource/FileSource.h +++ b/YUViewLib/src/filesource/FileSource.h @@ -55,11 +55,11 @@ enum class InputFormat }; constexpr EnumMapper InputFormatMapper = { - std::make_pair(InputFormat::Invalid, "Invalid"), - std::make_pair(InputFormat::AnnexBHEVC, "AnnexBHEVC"), - std::make_pair(InputFormat::AnnexBAVC, "AnnexBAVC"), - std::make_pair(InputFormat::AnnexBVVC, "AnnexBVVC"), - std::make_pair(InputFormat::Libav, "Libav")}; + std::make_pair(InputFormat::Invalid, "Invalid"), + std::make_pair(InputFormat::AnnexBHEVC, "AnnexBHEVC"), + std::make_pair(InputFormat::AnnexBAVC, "AnnexBAVC"), + std::make_pair(InputFormat::AnnexBVVC, "AnnexBVVC"), + std::make_pair(InputFormat::Libav, "Libav")}; /* The FileSource class provides functions for accessing files. Besides the reading of * certain blocks of the file, it also directly provides information on the file for the diff --git a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp index d3d2054fb..6bd169ef6 100644 --- a/YUViewLib/src/playlistitem/playlistItemRawFile.cpp +++ b/YUViewLib/src/playlistitem/playlistItemRawFile.cpp @@ -542,13 +542,18 @@ void playlistItemRawFile::loadRawData(int frameIdx) return; auto nrBytes = this->video->getBytesPerFrame(); + if (nrBytes < 0) + return; // Load the raw data for the given frameIdx from file and set it in the video int64_t fileStartPos; if (this->isY4MFile) fileStartPos = this->y4mFrameIndices.at(frameIdx); else - fileStartPos = frameIdx * nrBytes; + fileStartPos = static_cast(frameIdx) * nrBytes; + + if (fileStartPos < 0) + return; DEBUG_RAWFILE("playlistItemRawFile::loadRawData Start loading frame " << frameIdx << " bytes " << int(nrBytes)); diff --git a/YUViewLib/src/video/FrameHandler.cpp b/YUViewLib/src/video/FrameHandler.cpp index 2d995ca33..f7a37f0fd 100644 --- a/YUViewLib/src/video/FrameHandler.cpp +++ b/YUViewLib/src/video/FrameHandler.cpp @@ -124,10 +124,10 @@ QLayout *FrameHandler::createFrameHandlerControls(bool isSizeFixed) ui.setupUi(); // Set default values - ui.widthSpinBox->setMaximum(100000); + ui.widthSpinBox->setMaximum(Size::MAX_DIMENSION); ui.widthSpinBox->setValue(frameSize.width); ui.widthSpinBox->setEnabled(!isSizeFixed); - ui.heightSpinBox->setMaximum(100000); + ui.heightSpinBox->setMaximum(Size::MAX_DIMENSION); ui.heightSpinBox->setValue(frameSize.height); ui.heightSpinBox->setEnabled(!isSizeFixed); ui.frameSizeComboBox->addItems(presetFrameSizes.getFormattedNames()); From 14379b105a265e60e01c4ae276d407aa513ae931 Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Fri, 7 Aug 2026 18:25:48 +0200 Subject: [PATCH 2/4] Fix warning --- YUViewUnitTest/video/rgb/ConversionDifferenceRGBTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/YUViewUnitTest/video/rgb/ConversionDifferenceRGBTest.cpp b/YUViewUnitTest/video/rgb/ConversionDifferenceRGBTest.cpp index 9c80c5481..154ded80f 100644 --- a/YUViewUnitTest/video/rgb/ConversionDifferenceRGBTest.cpp +++ b/YUViewUnitTest/video/rgb/ConversionDifferenceRGBTest.cpp @@ -173,8 +173,8 @@ ExpectedImageAndMse generateExpectedImageAndMse(const FrameAandB &testFrames, .g = functions::clip(128 + diff.g * amplificationFactor, 0, 255), .b = functions::clip(128 + diff.b * amplificationFactor, 0, 255)}; - const auto x = i % TEST_FRAME_SIZE.width; - const auto y = i / TEST_FRAME_SIZE.width; + const auto x = static_cast(i % TEST_FRAME_SIZE.width); + const auto y = static_cast(i / TEST_FRAME_SIZE.width); image.setPixel(x, y, qRgb(outputPixel.r, outputPixel.g, outputPixel.b)); } From 0f4a3664b2636b3e28d0d02f9840763b5ecff30e Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Sun, 9 Aug 2026 11:20:39 +0200 Subject: [PATCH 3/4] Move Size and Offset into separate headers. Add tests. --- YUViewLib/src/common/Formatting.h | 1 + YUViewLib/src/common/Offset.h | 45 +++++++++ YUViewLib/src/common/Size.h | 60 ++++++++++++ YUViewLib/src/common/Typedef.h | 36 ------- YUViewLib/src/decoder/decoderTarga.h | 1 + YUViewLib/src/ffmpeg/AVCodecContextWrapper.h | 2 + .../src/ffmpeg/AVCodecParametersWrapper.h | 2 + YUViewLib/src/ffmpeg/AVFrameWrapper.h | 10 +- YUViewLib/src/filesource/FrameFormatGuess.h | 1 + YUViewLib/src/statistics/StatisticsData.h | 2 + YUViewLib/src/video/FrameHandler.h | 1 + YUViewLib/src/video/rgb/PixelFormatRGB.h | 5 +- YUViewLib/src/video/yuv/PixelFormatYUV.h | 5 +- YUViewUnitTest/common/OffsetTest.cpp | 0 YUViewUnitTest/common/SizeTest.cpp | 93 +++++++++++++++++++ YUViewUnitTest/common/Testing.h | 1 + 16 files changed, 223 insertions(+), 42 deletions(-) create mode 100644 YUViewLib/src/common/Offset.h create mode 100644 YUViewLib/src/common/Size.h create mode 100644 YUViewUnitTest/common/OffsetTest.cpp create mode 100644 YUViewUnitTest/common/SizeTest.cpp diff --git a/YUViewLib/src/common/Formatting.h b/YUViewLib/src/common/Formatting.h index 6696de333..381e4a9b3 100644 --- a/YUViewLib/src/common/Formatting.h +++ b/YUViewLib/src/common/Formatting.h @@ -32,6 +32,7 @@ #pragma once +#include "Size.h" #include "Typedef.h" #include diff --git a/YUViewLib/src/common/Offset.h b/YUViewLib/src/common/Offset.h new file mode 100644 index 000000000..c83a65910 --- /dev/null +++ b/YUViewLib/src/common/Offset.h @@ -0,0 +1,45 @@ +/* This file is part of YUView - The YUV player with advanced analytics toolset + * + * Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations including + * the two. + * + * You must obey the GNU General Public License in all respects for all + * of the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do + * so, delete this exception statement from your version. If you delete + * this exception statement from all source files in the program, then + * also delete it here. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +struct Offset +{ + Offset() = default; + Offset(int x, int y) : x(x), y(y) {} + + bool operator==(const Offset &other) const { return this->x == other.x && this->x == other.x; } + bool operator!=(const Offset &other) const { return this->x != other.x || this->y != other.y; } + + int x{}; + int y{}; +}; diff --git a/YUViewLib/src/common/Size.h b/YUViewLib/src/common/Size.h new file mode 100644 index 000000000..796e9ad84 --- /dev/null +++ b/YUViewLib/src/common/Size.h @@ -0,0 +1,60 @@ +/* This file is part of YUView - The YUV player with advanced analytics toolset + * + * Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations including + * the two. + * + * You must obey the GNU General Public License in all respects for all + * of the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do + * so, delete this exception statement from your version. If you delete + * this exception statement from all source files in the program, then + * also delete it here. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +struct Size +{ + static constexpr unsigned MAX_DIMENSION = 100000; + + constexpr Size(unsigned width, unsigned height) : width(width), height(height) {} + constexpr Size() = default; + + constexpr bool operator==(const Size &other) const + { + return this->width == other.width && this->height == other.height; + } + constexpr bool operator!=(const Size &other) const + { + return this->width != other.width || this->height != other.height; + } + + explicit operator bool() const { return this->isValid(); } + constexpr bool isValid() const + { + return this->width > 0 && this->width < MAX_DIMENSION && // + this->height > 0 && this->height < MAX_DIMENSION; + } + + unsigned width{}; + unsigned height{}; +}; diff --git a/YUViewLib/src/common/Typedef.h b/YUViewLib/src/common/Typedef.h index 6c2a3a0bf..82e54d918 100644 --- a/YUViewLib/src/common/Typedef.h +++ b/YUViewLib/src/common/Typedef.h @@ -182,42 +182,6 @@ struct Ratio int den{}; }; -struct Size -{ - static constexpr unsigned MAX_DIMENSION = 100000; - - constexpr Size(unsigned width, unsigned height) : width(width), height(height) {} - constexpr Size() = default; - - constexpr bool operator==(const Size &other) const - { - return this->width == other.width && this->height == other.height; - } - constexpr bool operator!=(const Size &other) const - { - return this->width != other.width || this->height != other.height; - } - explicit operator bool() const { return this->isValid(); } - constexpr bool isValid() const - { - return this->width > 0 && this->width < MAX_DIMENSION && // - this->height > 0 && this->height < MAX_DIMENSION; - } - - unsigned width{}; - unsigned height{}; -}; - -struct Offset -{ - Offset(int x, int y) : x(x), y(y) {} - Offset() = default; - bool operator==(const Offset &other) const { return this->x == other.x && this->x == other.x; } - bool operator!=(const Offset &other) const { return this->x != other.x || this->y != other.y; } - int x{}; - int y{}; -}; - // A list of value pair lists, where every list has a string (title) class ValuePairListSets : public QList> { diff --git a/YUViewLib/src/decoder/decoderTarga.h b/YUViewLib/src/decoder/decoderTarga.h index 2a19b808f..b8a639936 100644 --- a/YUViewLib/src/decoder/decoderTarga.h +++ b/YUViewLib/src/decoder/decoderTarga.h @@ -32,6 +32,7 @@ #pragma once +#include #include #include diff --git a/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h b/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h index 760f6a171..b01611bbc 100644 --- a/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h +++ b/YUViewLib/src/ffmpeg/AVCodecContextWrapper.h @@ -33,6 +33,8 @@ #pragma once #include "FFMpegLibrariesTypes.h" + +#include #include namespace FFmpeg diff --git a/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h b/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h index 3542e11bb..898783f0c 100644 --- a/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h +++ b/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.h @@ -33,6 +33,8 @@ #pragma once #include "FFMpegLibrariesTypes.h" + +#include #include namespace FFmpeg diff --git a/YUViewLib/src/ffmpeg/AVFrameWrapper.h b/YUViewLib/src/ffmpeg/AVFrameWrapper.h index 72b3998fc..0fbe050f4 100644 --- a/YUViewLib/src/ffmpeg/AVFrameWrapper.h +++ b/YUViewLib/src/ffmpeg/AVFrameWrapper.h @@ -33,6 +33,8 @@ #pragma once #include "FFMpegLibrariesTypes.h" + +#include #include namespace FFmpeg @@ -47,9 +49,9 @@ class AVFrameWrapper void clear(); - uint8_t * getData(int component); + uint8_t *getData(int component); int getLineSize(int component); - AVFrame * getFrame() const; + AVFrame *getFrame() const; int getWidth(); int getHeight(); Size getSize(); @@ -64,7 +66,7 @@ class AVFrameWrapper void update(); // These are private. Use "update" to update them from the AVFormatContext - uint8_t * data[AV_NUM_DATA_POINTERS]{}; + uint8_t *data[AV_NUM_DATA_POINTERS]{}; int linesize[AV_NUM_DATA_POINTERS]{}; int width{}; int height{}; @@ -81,7 +83,7 @@ class AVFrameWrapper int quality{}; AVDictionary *metadata{}; - AVFrame * frame{}; + AVFrame *frame{}; LibraryVersion libVer{}; }; diff --git a/YUViewLib/src/filesource/FrameFormatGuess.h b/YUViewLib/src/filesource/FrameFormatGuess.h index 104ccd306..edb8f621b 100644 --- a/YUViewLib/src/filesource/FrameFormatGuess.h +++ b/YUViewLib/src/filesource/FrameFormatGuess.h @@ -32,6 +32,7 @@ #pragma once +#include #include #include