Skip to content

Commit 8abb932

Browse files
committed
Fix double free in Cu6mPlayer::~Cu6mPlayer() (issue adplug#91)
Leave deallocation of song_data to destructor when decompression fails, just like on success. This fixes CVE-2019-15151. Even though load() is apparently not supposed to be called twice (and bad things happen in many players if you do), let's also avoid leaking song_data's memory in that case. Fixes: adplug#91
1 parent 8f0e614 commit 8abb932

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/u6m.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ bool Cu6mPlayer::load(const std::string &filename, const CFileProvider &fp)
6666
}
6767

6868
// load section
69+
delete[] song_data;
6970
song_data = new unsigned char[decompressed_filesize];
7071
unsigned char* compressed_song_data = new unsigned char[filesize-3];
7172

@@ -74,7 +75,6 @@ bool Cu6mPlayer::load(const std::string &filename, const CFileProvider &fp)
7475
fp.close(f);
7576

7677
// attempt to decompress the song data
77-
// if unsuccessful, deallocate song_data[] on the spot, and return(false)
7878
data_block source, destination;
7979
source.size = filesize-4;
8080
source.data = compressed_song_data;
@@ -84,7 +84,6 @@ bool Cu6mPlayer::load(const std::string &filename, const CFileProvider &fp)
8484
if (!lzw_decompress(source,destination))
8585
{
8686
delete[] compressed_song_data;
87-
delete[] song_data;
8887
return(false);
8988
}
9089

0 commit comments

Comments
 (0)