Skip to content

Commit

Permalink
Fix segfault for compressed EPG files
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed Aug 31, 2019
1 parent 9dd322e commit c0eefcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/iptvsimple/Epg.cpp
Expand Up @@ -79,7 +79,8 @@ bool Epg::LoadEPG(time_t start, time_t end)

if (GetXMLTVFileWithRetries(data))
{
char* buffer = FillBufferFromXMLTVData(data);
std::string decompressedData;
char* buffer = FillBufferFromXMLTVData(data, decompressedData);

if (!buffer)
return false;
Expand Down Expand Up @@ -152,24 +153,23 @@ bool Epg::GetXMLTVFileWithRetries(std::string& data)
return true;
}

char* Epg::FillBufferFromXMLTVData(std::string& data)
char* Epg::FillBufferFromXMLTVData(std::string& data, std::string& decompressedData)
{
std::string decompressed;
char* buffer = nullptr;

// gzip packed
if (data[0] == '\x1F' && data[1] == '\x8B' && data[2] == '\x08')
{
if (!FileUtils::GzipInflate(data, decompressed))
if (!FileUtils::GzipInflate(data, decompressedData))
{
Logger::Log(LEVEL_ERROR, "%s - Invalid EPG file '%s': unable to decompress file.", __FUNCTION__, m_xmltvLocation.c_str());
return nullptr;
}
buffer = &(decompressed[0]);
buffer = &(decompressedData[0]);
}
else
{
buffer = &(data[0]);
buffer = &(data[0]);
}

XmltvFileFormat fileFormat = GetXMLTVFileFormat(buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/iptvsimple/Epg.h
Expand Up @@ -60,7 +60,7 @@ namespace iptvsimple

bool LoadEPG(time_t iStart, time_t iEnd);
bool GetXMLTVFileWithRetries(std::string& data);
char* FillBufferFromXMLTVData(std::string& data);
char* FillBufferFromXMLTVData(std::string& data, std::string& decompressedData);
bool LoadChannelEpgs(rapidxml::xml_node<>* rootElement);
void LoadEpgEntries(rapidxml::xml_node<>* rootElement, int start, int end);
bool LoadGenres();
Expand Down

0 comments on commit c0eefcb

Please sign in to comment.