From b00548440b4d37ee2806f0760a949b23b7e14aa8 Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Tue, 25 Jun 2024 20:51:29 +0200 Subject: [PATCH] [BH-2020] Fix double-free in DecoderMP3 Fix of the issue that improper check of dr_mp3 library initialization success could result in double-free of library internals in case initialization was unsuccessful. --- module-audio/Audio/decoder/DecoderMP3.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/module-audio/Audio/decoder/DecoderMP3.cpp b/module-audio/Audio/decoder/DecoderMP3.cpp index 917cebbf98e5fd09e79eb970d703f927b2b5e0fc..92291500faf4449bde4181ab78cf3cb4965cf4f1 100644 --- a/module-audio/Audio/decoder/DecoderMP3.cpp +++ b/module-audio/Audio/decoder/DecoderMP3.cpp @@ -49,7 +49,7 @@ namespace namespace audio { - DecoderMP3::DecoderMP3(const std::string &filePath) : Decoder(filePath) + DecoderMP3::DecoderMP3(const std::string &filePath) : Decoder(filePath), mp3(std::make_unique()) { if (fileSize == 0) { return; @@ -63,10 +63,7 @@ namespace audio LOG_INFO("No ID3V2 tag to skip"); } - mp3 = std::make_unique(); - - drmp3_init(mp3.get(), drmp3Read, drmp3Seek, this, nullptr); - if (mp3 == nullptr) { + if (drmp3_init(mp3.get(), drmp3Read, drmp3Seek, this, nullptr) == DRMP3_FALSE) { LOG_ERROR("Unable to initialize MP3 decoder"); return; } @@ -80,7 +77,11 @@ namespace audio DecoderMP3::~DecoderMP3() { + if (!isInitialized) { + return; + } drmp3_uninit(mp3.get()); + isInitialized = false; } void DecoderMP3::setPosition(float pos)