Skip to content

Commit

Permalink
Merge pull request #902 from phunkyfish/fix-xml-file-format-check
Browse files Browse the repository at this point in the history
Fix xml file format check
  • Loading branch information
phunkyfish authored Oct 8, 2024
2 parents d0b4e97 + 9e7fa68 commit 19dc2e0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pvr.iptvsimple/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.iptvsimple"
version="22.2.0"
version="22.2.1"
name="IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand Down
4 changes: 4 additions & 0 deletions pvr.iptvsimple/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v22.2.1
- Fix XML file format check
- Always treat special paths as local

v22.2.0
- Correctly set inputstream properties for media entries

Expand Down
26 changes: 14 additions & 12 deletions src/iptvsimple/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,21 @@ 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
7 changes: 6 additions & 1 deletion src/iptvsimple/utilities/WebUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ bool WebUtils::IsNfsUrl(const std::string& url)
return StringUtils::StartsWith(url, NFS_PREFIX);
}

bool WebUtils::IsSpecialUrl(const std::string& url)
{
return StringUtils::StartsWith(url, SPECIAL_PREFIX);
}

std::string WebUtils::RedactUrl(const std::string& url)
{
std::string redactedUrl = url;
Expand All @@ -139,7 +144,7 @@ std::string WebUtils::RedactUrl(const std::string& url)
bool WebUtils::Check(const std::string& strURL, int connectionTimeoutSecs, bool isLocalPath)
{
// For local paths we only need to check existence of the file
if (isLocalPath && FileUtils::FileExists(strURL))
if ((isLocalPath || IsSpecialUrl(strURL)) && FileUtils::FileExists(strURL))
return true;

//Otherwise it's remote
Expand Down
2 changes: 2 additions & 0 deletions src/iptvsimple/utilities/WebUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace iptvsimple
static const std::string HTTP_PREFIX = "http://";
static const std::string HTTPS_PREFIX = "https://";
static const std::string NFS_PREFIX = "nfs://";
static const std::string SPECIAL_PREFIX = "special://";
static const std::string UDP_MULTICAST_PREFIX = "udp://@";
static const std::string RTP_MULTICAST_PREFIX = "rtp://@";

Expand All @@ -28,6 +29,7 @@ namespace iptvsimple
static std::string ReadFileContentsStartOnly(const std::string& url, int* httpCode);
static bool IsHttpUrl(const std::string& url);
static bool IsNfsUrl(const std::string& url);
static bool IsSpecialUrl(const std::string& url);
static std::string RedactUrl(const std::string& url);
static bool Check(const std::string& url, int connectionTimeoutSecs, bool isLocalPath = false);
};
Expand Down

0 comments on commit 19dc2e0

Please sign in to comment.