Merge pull request #62456 from qgis/backport-62438-to-release-3_44

[Backport release-3_44] Fix overflow in vector tile long int attributes
This commit is contained in:
Alexander Bruy 2025-06-28 06:14:50 +01:00 committed by GitHub
commit dcda57ec86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 3 deletions

View File

@ -206,11 +206,11 @@ QgsVectorTileFeatures QgsVectorTileMVTDecoder::layerFeatures( const QMap<QString
else if ( value.has_double_value() ) else if ( value.has_double_value() )
f.setAttribute( fieldIndex, value.double_value() ); f.setAttribute( fieldIndex, value.double_value() );
else if ( value.has_int_value() ) else if ( value.has_int_value() )
f.setAttribute( fieldIndex, static_cast<int>( value.int_value() ) ); f.setAttribute( fieldIndex, static_cast<long long>( value.int_value() ) );
else if ( value.has_uint_value() ) else if ( value.has_uint_value() )
f.setAttribute( fieldIndex, static_cast<int>( value.uint_value() ) ); f.setAttribute( fieldIndex, static_cast<long long>( value.uint_value() ) );
else if ( value.has_sint_value() ) else if ( value.has_sint_value() )
f.setAttribute( fieldIndex, static_cast<int>( value.sint_value() ) ); f.setAttribute( fieldIndex, static_cast<long long>( value.sint_value() ) );
else if ( value.has_bool_value() ) else if ( value.has_bool_value() )
f.setAttribute( fieldIndex, static_cast<bool>( value.bool_value() ) ); f.setAttribute( fieldIndex, static_cast<bool>( value.bool_value() ) );
else else

View File

@ -36,6 +36,7 @@
#include "qgsprovidersublayerdetails.h" #include "qgsprovidersublayerdetails.h"
#include "qgsproviderutils.h" #include "qgsproviderutils.h"
#include "qgsvectortileloader.h" #include "qgsvectortileloader.h"
#include "qgsvectortilemvtdecoder.h"
/** /**
* \ingroup UnitTests * \ingroup UnitTests
@ -81,6 +82,8 @@ class TestQgsVectorTileLayer : public QgsTest
void test_styleMinZoomBeyondTileMaxZoom(); void test_styleMinZoomBeyondTileMaxZoom();
void test_filterRuleAllLayers(); void test_filterRuleAllLayers();
void test_longIntAttributes();
}; };
@ -698,6 +701,35 @@ void TestQgsVectorTileLayer::test_filterRuleAllLayers()
QGSVERIFYRENDERMAPSETTINGSCHECK( QStringLiteral( "render_test_filter_all_layers" ), QStringLiteral( "render_test_filter_all_layers" ), *mMapSettings, 0, 15 ); QGSVERIFYRENDERMAPSETTINGSCHECK( QStringLiteral( "render_test_filter_all_layers" ), QStringLiteral( "render_test_filter_all_layers" ), *mMapSettings, 0, 15 );
} }
void TestQgsVectorTileLayer::test_longIntAttributes()
{
// test using a filter with field access for an "all layers" rule
QgsDataSourceUri ds;
ds.setParam( "type", "mbtiles" );
ds.setParam( "url", QString( "/%1/longint.mbtiles" ).arg( mDataDir ) );
auto layer = std::make_unique<QgsVectorTileLayer>( ds.encodedUri(), "Vector Tiles Test" );
QVERIFY( layer->isValid() );
const QgsVectorTileRawData tile0 = layer->getRawTile( QgsTileXYZ( 0, 0, 0 ) );
QgsVectorTileMVTDecoder decoder( QgsVectorTileMatrixSet::fromWebMercator() );
const bool resDecode0 = decoder.decode( tile0 );
QVERIFY( resDecode0 );
const QStringList fieldNamesLines = decoder.layerFieldNames( "lines" );
QCOMPARE( fieldNamesLines, QStringList() << "Name" << "Value" );
QgsFields fields;
fields.append( QgsField( "Value", QMetaType::Type::QString ) );
QMap<QString, QgsFields> perLayerFields;
perLayerFields["lines"] = fields;
QgsVectorTileFeatures features = decoder.layerFeatures( perLayerFields, QgsCoordinateTransform() );
QCOMPARE( features["lines"].count(), 1 );
QgsAttributes attrs = features["lines"][0].attributes();
QCOMPARE( attrs.count(), 1 );
QCOMPARE( attrs[0].toString(), "103097205262536" );
}
QGSTEST_MAIN( TestQgsVectorTileLayer ) QGSTEST_MAIN( TestQgsVectorTileLayer )
#include "testqgsvectortilelayer.moc" #include "testqgsvectortilelayer.moc"

Binary file not shown.