Skip to content

Commit

Permalink
Fix XML file format check
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed Oct 7, 2024
1 parent d0b4e97 commit 7ba7272
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/iptvsimple/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,22 @@ const XmltvFileFormat Epg::GetXMLTVFileFormat(const char* buffer)
if (!buffer)
return XmltvFileFormat::INVALID;

// xml should starts with '<?xml'
if (buffer[0] != '\x3C' || buffer[1] != '\x3F' || buffer[2] != '\x78' ||
buffer[3] != '\x6D' || buffer[4] != '\x6C')
if ((buffer[0] != '\x3C' && buffer[std::strlen(buffer) - 1] != '\x3E') || // Start with < and ends with >
(buffer[0] != '\x3C' && buffer[1] != '\x3F' && buffer[2] != '\x78' && // xml should starts with '<?xml'
buffer[3] != '\x6D' && buffer[4] != '\x6C'
)
{
// check for BOM
if (buffer[0] != '\xEF' || buffer[1] != '\xBB' || buffer[2] != '\xBF')
{
// check for tar archive
if (strcmp(buffer + 0x101, "ustar") || strcmp(buffer + 0x101, "GNUtar"))
return XmltvFileFormat::TAR_ARCHIVE;
else
return XmltvFileFormat::INVALID;
}
return XmltvFileFormat::NORMAL;
}

// check for BOM
if (buffer[0] != '\xEF' || buffer[1] != '\xBB' || buffer[2] != '\xBF')
{
// check for tar archive
if (strcmp(buffer + 0x101, "ustar") || strcmp(buffer + 0x101, "GNUtar"))
return XmltvFileFormat::TAR_ARCHIVE;
else
return XmltvFileFormat::INVALID;
}

return XmltvFileFormat::NORMAL;
Expand Down

0 comments on commit 7ba7272

Please sign in to comment.