[vlc-commits] [Git][videolan/vlc][master] qt: fix out of bound when deleting range from model

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jun 19 13:10:31 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
66f7cebc by Pierre Lamot at 2023-06-19T12:25:36+00:00
qt: fix out of bound when deleting range from model

view may request data that are not loaded in then cache to be deleted

- - - - -


1 changed file:

- modules/gui/qt/medialibrary/mllistcache.cpp


Changes:

=====================================
modules/gui/qt/medialibrary/mllistcache.cpp
=====================================
@@ -230,14 +230,26 @@ void MLListCache::deleteRange(int first, int last)
 {
     if (unlikely(!m_cachedData))
         return;
-
     assert(first <= last);
+    assert(first >= 0);
+    assert(static_cast<size_t>(last) < m_cachedData->totalCount);
     emit beginRemoveRows(first, last);
-    auto it = m_cachedData->list.begin();
-    m_cachedData->list.erase(it+first, it+(last+1));
-    size_t delta = m_cachedData->loadedCount - m_cachedData->list.size();
-    m_cachedData->loadedCount -= delta;
-    m_cachedData->totalCount -= delta;
+    if (static_cast<size_t>(first) < m_cachedData->loadedCount)
+    {
+        auto itFirst = std::next(m_cachedData->list.begin(), first);
+
+        auto itLast = m_cachedData->list.begin();
+        if (static_cast<size_t>(last) < m_cachedData->loadedCount)
+            itLast = std::next(itLast, last + 1);
+        else
+            itLast = m_cachedData->list.end();
+
+        m_cachedData->list.erase(itFirst, itLast);
+        m_cachedData->loadedCount = m_cachedData->list.size();
+    }
+    //else data are not loaded, just mark them as deleted
+
+    m_cachedData->totalCount -= (last + 1) - first;
     emit endRemoveRows();
     emit localSizeChanged(m_cachedData->totalCount);
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/66f7cebc2ee4f15abb2d66fa315a2c15daf59ad7

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/66f7cebc2ee4f15abb2d66fa315a2c15daf59ad7
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list