Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use-after-free in QgsVectorLayerCache iterators #58093

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/qgscachedfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool QgsCachedFeatureIterator::fetchFeature( QgsFeature &f )
{
f.setValid( false );

if ( mClosed )
if ( mClosed || !mVectorLayerCache )
return false;

while ( mFeatureIdIterator != mFeatureIds.constEnd() )
Expand Down Expand Up @@ -168,7 +168,7 @@ QgsCachedFeatureWriterIterator::QgsCachedFeatureWriterIterator( QgsVectorLayerCa

bool QgsCachedFeatureWriterIterator::fetchFeature( QgsFeature &f )
{
if ( mClosed )
if ( mClosed || !mVectorLayerCache )
{
f.setValid( false );
return false;
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgscachedfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "qgsfeature.h"
#include "qgsfeatureiterator.h"
#include "qgscoordinatetransform.h"
#include "qgsvectorlayercache.h"
#include <QPointer>

class QgsVectorLayerCache;

Expand Down Expand Up @@ -84,7 +86,7 @@ class CORE_EXPORT QgsCachedFeatureIterator : public QgsAbstractFeatureIterator
#endif

QList< QgsFeatureId > mFeatureIds;
QgsVectorLayerCache *mVectorLayerCache = nullptr;
QPointer< QgsVectorLayerCache > mVectorLayerCache = nullptr;
QList< QgsFeatureId >::ConstIterator mFeatureIdIterator;
QgsCoordinateTransform mTransform;
QgsRectangle mFilterRect;
Expand Down Expand Up @@ -140,7 +142,7 @@ class CORE_EXPORT QgsCachedFeatureWriterIterator : public QgsAbstractFeatureIter

private:
QgsFeatureIterator mFeatIt;
QgsVectorLayerCache *mVectorLayerCache = nullptr;
QPointer< QgsVectorLayerCache > mVectorLayerCache;
QgsFeatureIds mFids;
QgsCoordinateTransform mTransform;
QgsRectangle mFilterRect;
Expand Down
6 changes: 6 additions & 0 deletions tests/src/python/test_qgsvectorlayercache.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def testAllFeatureIds(self):
"""
pass

def testOpenIteratorAfterSourceRemoval(self):
"""
Skip this test -- the iterators from the cache CANNOT be used after the cache is deleted
"""
pass


if __name__ == '__main__':
unittest.main()
Loading