Skip to content

Commit 32270fc

Browse files
authoredAug 2, 2021
Merge pull request #44510 from mhugent/backport_3_16_max_image_width
Backport 3_16 max image width/height for GetLegendGraphic
2 parents dce8b2d + 2a7d6c7 commit 32270fc

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed
 

‎src/server/services/wms/qgswmsrendercontext.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ int QgsWmsRenderContext::mapHeight() const
616616
}
617617

618618
bool QgsWmsRenderContext::isValidWidthHeight() const
619+
{
620+
return isValidWidthHeight( mapWidth(), mapHeight() );
621+
}
622+
623+
bool QgsWmsRenderContext::isValidWidthHeight( int width, int height ) const
619624
{
620625
//test if maxWidth / maxHeight are set in the project or as an env variable
621626
//and WIDTH / HEIGHT parameter is in the range allowed range
@@ -634,7 +639,7 @@ bool QgsWmsRenderContext::isValidWidthHeight() const
634639
wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
635640
}
636641

637-
if ( wmsMaxWidth != -1 && mapWidth() > wmsMaxWidth )
642+
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
638643
{
639644
return false;
640645
}
@@ -654,7 +659,7 @@ bool QgsWmsRenderContext::isValidWidthHeight() const
654659
wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
655660
}
656661

657-
if ( wmsMaxHeight != -1 && mapHeight() > wmsMaxHeight )
662+
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
658663
{
659664
return false;
660665
}
@@ -675,13 +680,13 @@ bool QgsWmsRenderContext::isValidWidthHeight() const
675680
depth = 32;
676681
}
677682

678-
const int bytes_per_line = ( ( mapWidth() * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
683+
const int bytes_per_line = ( ( width * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
679684

680-
if ( std::numeric_limits<int>::max() / depth < static_cast<uint>( mapWidth() )
685+
if ( std::numeric_limits<int>::max() / depth < static_cast<uint>( width )
681686
|| bytes_per_line <= 0
682-
|| mapHeight() <= 0
683-
|| std::numeric_limits<int>::max() / static_cast<uint>( bytes_per_line ) < static_cast<uint>( mapHeight() )
684-
|| std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( mapHeight() ) )
687+
|| height <= 0
688+
|| std::numeric_limits<int>::max() / static_cast<uint>( bytes_per_line ) < static_cast<uint>( height )
689+
|| std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( height ) )
685690
{
686691
return false;
687692
}

‎src/server/services/wms/qgswmsrendercontext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ namespace QgsWms
235235
*/
236236
bool isValidWidthHeight() const;
237237

238+
/**
239+
* Returns true if width and height are valid according to the maximum image width/height
240+
* \param width the image width in pixels
241+
* \param height the image height in pixels
242+
* \since QGIS 3.22
243+
*/
244+
bool isValidWidthHeight( int width, int height ) const;
245+
238246
/**
239247
* Returns WIDTH or SRCWIDTH according to \a UseSrcWidthHeight flag.
240248
*/

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ namespace QgsWms
128128
const qreal dpmm = mContext.dotsPerMm();
129129
const QSizeF minSize = renderer.minimumSize();
130130
const QSize size( static_cast<int>( minSize.width() * dpmm ), static_cast<int>( minSize.height() * dpmm ) );
131+
if ( !mContext.isValidWidthHeight( size.width(), size.height() ) )
132+
{
133+
throw QgsServerException( QStringLiteral( "Legend image is too large" ) );
134+
}
131135
image.reset( createImage( size ) );
132136

133137
// configure painter
@@ -160,6 +164,11 @@ namespace QgsWms
160164

161165
// create image
162166
const QSize size( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt() );
167+
//test if legend image is larger than max width/height
168+
if ( !mContext.isValidWidthHeight( size.width(), size.height() ) )
169+
{
170+
throw QgsServerException( QStringLiteral( "Legend image is too large" ) );
171+
}
163172
std::unique_ptr<QImage> image( createImage( size ) );
164173

165174
// configure painter

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@
20982098
<item row="0" column="0" colspan="5">
20992099
<widget class="QLabel" name="label_21">
21002100
<property name="text">
2101-
<string>Maximums for GetMap request</string>
2101+
<string>Maximum image size for GetMap and GetLegendGraphic requests</string>
21022102
</property>
21032103
</widget>
21042104
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.