meta_engine: taglib: add sequential read limit on VlcIostream
authorFrançois Cartegnie <fcvlcdev@free.fr>
Mon, 10 Aug 2020 12:52:11 +0000 (14:52 +0200)
committerSebastian Ramacher <sramacher@debian.org>
Tue, 14 Jan 2025 22:09:47 +0000 (23:09 +0100)
(cherry picked from commit d375284a144e6b18896deda3a86b9560bc04f3d8) (rebased)
rebased:
- 3.0 already has 1.11 ifdef

Gbp-Pq: Name 0040-meta_engine-taglib-add-sequential-read-limit-on-VlcI.patch

modules/meta_engine/taglib.cpp

index 58d7683cf90f605f08e5291ec8c0f57995be064c..a52c67c928fda5a37e70cb9a79b613a4d37d42f5 100644 (file)
@@ -99,6 +99,7 @@ using namespace TagLib;
 
 
 #include <algorithm>
+#include <limits>
 
 namespace VLCTagLib
 {
@@ -167,6 +168,8 @@ public:
         : m_stream( p_stream )
         , m_previousPos( 0 )
         , m_borked( false )
+        , m_seqReadLength( 0 )
+        , m_seqReadLimit( std::numeric_limits<long>::max() )
     {
     }
 
@@ -184,7 +187,7 @@ public:
 
     ByteVector readBlock(ulong length)
     {
-        if(m_borked)
+        if(m_borked || m_seqReadLength >= m_seqReadLimit)
            return ByteVector::null;
         ByteVector res(length, 0);
         ssize_t i_read = vlc_stream_Read( m_stream, res.data(), length);
@@ -193,6 +196,7 @@ public:
         else if ((size_t)i_read != length)
             res.resize(i_read);
         m_previousPos += i_read;
+        m_seqReadLength += i_read;
         return res;
     }
 
@@ -219,6 +223,11 @@ public:
         return true;
     }
 
+    void setMaxSequentialRead(long s)
+    {
+        m_seqReadLimit = s;
+    }
+
     void seek(long offset, Position p)
     {
         uint64_t pos = 0;
@@ -246,6 +255,7 @@ public:
         m_borked = (vlc_stream_Seek( m_stream, pos + offset ) != 0);
         if(!m_borked)
             m_previousPos = pos + offset;
+        m_seqReadLength = 0;
     }
 
     void clear()
@@ -274,6 +284,8 @@ private:
     stream_t* m_stream;
     int64_t m_previousPos;
     bool m_borked;
+    long m_seqReadLength;
+    long m_seqReadLimit;
 };
 #endif /* TAGLIB_VERSION_1_11 */