Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix container out of bounds access errors
  • Loading branch information
nyalldawson committed Apr 17, 2023
1 parent 42decb1 commit 71f32ca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/core/geometry/qgsgeometrycollection.cpp
Expand Up @@ -1061,8 +1061,9 @@ int QgsGeometryCollection::childCount() const

QgsAbstractGeometry *QgsGeometryCollection::childGeometry( int index ) const
{
if ( index < 0 || index > mGeometries.count() )
if ( index < 0 || index >= mGeometries.count() )
return nullptr;

return mGeometries.at( index );
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/mesh/qgstopologicalmesh.cpp
Expand Up @@ -278,7 +278,7 @@ int QgsMeshVertexCirculator::degree() const

int QgsMeshVertexCirculator::positionInCurrentFace() const
{
if ( mCurrentFace < 0 || mCurrentFace > mFaces.count() )
if ( mCurrentFace < 0 || mCurrentFace >= mFaces.count() )
return -1;

return vertexPositionInFace( mVertexIndex, mFaces.at( mCurrentFace ) );
Expand Down
12 changes: 8 additions & 4 deletions src/core/qgspostgresstringutils.cpp
Expand Up @@ -74,18 +74,22 @@ QVariantList QgsPostgresStringUtils::parseArray( const QString &string )
if ( newVal.trimmed().startsWith( '{' ) )
{
//it's a multidimensional array
QString subarray = newVal;
QString subarray = newVal.trimmed();
while ( !subarray.isEmpty() )
{
bool escaped = false;
int openedBrackets = 1;
int i = 0;
while ( i < subarray.length() && openedBrackets > 0 )
while ( openedBrackets > 0 )
{
++i;
if ( i >= subarray.length() )
break;

if ( subarray.at( i ) == '}' && !escaped ) openedBrackets--;
else if ( subarray.at( i ) == '{' && !escaped ) openedBrackets++;
if ( subarray.at( i ) == '}' && !escaped )
openedBrackets--;
else if ( subarray.at( i ) == '{' && !escaped )
openedBrackets++;

escaped = !escaped ? subarray.at( i ) == '\\' : false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/vectortile/qgsvectortilemvtencoder.cpp
Expand Up @@ -106,6 +106,8 @@ static void encodeLineString( const QgsLineString *lineString, bool isRing, bool
last = pt;
}
count = tilePoints.count();
if ( count == 0 )
return;

geomWriter.addMoveTo( 1 );
geomWriter.addPoint( tilePoints[0] );
Expand Down

0 comments on commit 71f32ca

Please sign in to comment.