aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmarshallnz <jcmarsha@gmail.com>2014-06-10 21:54:47 +1200
committerjmarshallnz <jcmarsha@gmail.com>2014-06-10 21:54:47 +1200
commit90c779e35fdf215412113fa2751a81417711452e (patch)
treef2f97449fbc6a0085fe05b65fcb7b7cafb2ef586
parent10af0db6c0db184fe3ec0e49e09f07f2f590cc19 (diff)
parent2b993aa799a396180ee442505cf52ba3d21f9994 (diff)
Merge pull request #4797 from Karlson2k/Gotham-fix_tag_read
Gotham: fix tag read
-rw-r--r--xbmc/music/tags/TagLibVFSStream.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/xbmc/music/tags/TagLibVFSStream.cpp b/xbmc/music/tags/TagLibVFSStream.cpp
index 3d52ae9ffc..e2abcd5b2a 100644
--- a/xbmc/music/tags/TagLibVFSStream.cpp
+++ b/xbmc/music/tags/TagLibVFSStream.cpp
@@ -51,6 +51,7 @@ TagLibVFSStream::TagLibVFSStream(const string& strFileName, bool readOnly)
m_bIsOpen = false;
}
m_strFileName = strFileName;
+ m_bIsReadOnly = readOnly || !m_bIsOpen;
}
/*!
@@ -239,6 +240,38 @@ bool TagLibVFSStream::isOpen() const
*/
void TagLibVFSStream::seek(long offset, Position p)
{
+ const long fileLen = length();
+ if (m_bIsReadOnly && fileLen > 0)
+ {
+ long startPos;
+ if (p == Beginning)
+ startPos = 0;
+ else if (p == Current)
+ startPos = tell();
+ else if (p == End)
+ startPos = fileLen;
+ else
+ return; // wrong Position value
+
+ // When parsing some broken files, taglib may try to seek above end of file.
+ // If underlying VFS does not move I/O pointer in this case, taglib will parse
+ // same part of file several times and ends with error. To prevent this
+ // situation, force seek to last valid position so VFS move I/O pointer.
+ if (startPos >= 0)
+ {
+ if (offset < 0 && startPos + offset < 0)
+ {
+ m_file.Seek(0, SEEK_SET);
+ return;
+ }
+ if (offset > 0 && startPos + offset > fileLen)
+ {
+ m_file.Seek(fileLen, SEEK_SET);
+ return;
+ }
+ }
+ }
+
switch(p)
{
case Beginning: