Merge pull request #1163 from theverygaming/master

fixed buffer overflow in file source
pull/1183/head
AlexandreRouma 2023-09-13 03:43:45 +02:00 zatwierdzone przez GitHub
commit 27b07ed0e8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 15 dodań i 6 usunięć

Wyświetl plik

@ -1,3 +1,4 @@
#define NOMINMAX
#include <imgui.h>
#include <utils/flog.h>
#include <module.h>
@ -9,6 +10,8 @@
#include <filesystem>
#include <regex>
#include <gui/tuner.h>
#include <algorithm>
#include <stdexcept>
#define CONCAT(a, b) ((std::string(a) + b).c_str())
@ -121,6 +124,12 @@ private:
}
try {
_this->reader = new WavReader(_this->fileSelect.path);
if (_this->reader->getSampleRate() == 0) {
_this->reader->close();
delete _this->reader;
_this->reader = NULL;
throw std::runtime_error("Sample rate may not be zero");
}
_this->sampleRate = _this->reader->getSampleRate();
core::setInputSampleRate(_this->sampleRate);
std::string filename = std::filesystem::path(_this->fileSelect.path).filename().string();
@ -130,7 +139,7 @@ private:
//gui::freqSelect.maxFreq = _this->centerFreq + (_this->sampleRate/2);
//gui::freqSelect.limitFreq = true;
}
catch (std::exception e) {
catch (std::exception& e) {
flog::error("Error: {0}", e.what());
}
config.acquire();
@ -144,8 +153,8 @@ private:
static void worker(void* ctx) {
FileSourceModule* _this = (FileSourceModule*)ctx;
double sampleRate = _this->reader->getSampleRate();
int blockSize = sampleRate / 200.0f;
double sampleRate = std::max(_this->reader->getSampleRate(), (uint32_t)1);
int blockSize = std::min((int)(sampleRate / 200.0f), (int)STREAM_BUFFER_SIZE);
int16_t* inBuf = new int16_t[blockSize * 2];
while (true) {
@ -159,8 +168,8 @@ private:
static void floatWorker(void* ctx) {
FileSourceModule* _this = (FileSourceModule*)ctx;
double sampleRate = _this->reader->getSampleRate();
int blockSize = sampleRate / 200.0f;
double sampleRate = std::max(_this->reader->getSampleRate(), (uint32_t)1);
int blockSize = std::min((int)(sampleRate / 200.0f), (int)STREAM_BUFFER_SIZE);
dsp::complex_t* inBuf = new dsp::complex_t[blockSize];
while (true) {
@ -214,4 +223,4 @@ MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
MOD_EXPORT void _END_() {
config.disableAutoSave();
config.save();
}
}