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

QgsRasterDataProvider.block() returns invalid QgsRasterBlock if requested block size exceeds a certain threshold #47097

Closed
2 tasks done
janzandr opened this issue Jan 31, 2022 · 2 comments · Fixed by #47106
Closed
2 tasks done
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API Rasters Related to general raster layer handling (not specific data formats)

Comments

@janzandr
Copy link

What is the bug or the crash?

For any GDAL raster layer, the QgsRasterDataProvider.block() returns an invalid QgsRasterBlock, if requested block size exceeds a certain threshold.

Steps to reproduce the issue

  1. Open a GDAL raster layer in QGIS, e.g. the dem.tif testdata: \QGIS3-master\tests\testdata\qgis_server_accesscontrol\dem.tif
  2. In the Python Console execute:
    >>>iface.activeLayer().dataProvider().block(1, iface.mapCanvas().extent(), 65000, 50000).isValid()
    False

Note that for slightly smaller block sizes, everything works fine:
>>>iface.activeLayer().dataProvider().block(1, iface.mapCanvas().extent(), 60000, 50000).isValid()
True

Versions

QGIS version
3.22.1-Białowieża
QGIS code revision
663dcf8
Qt version
5.15.2
Python version
3.9.5
GDAL/OGR version
3.4.0
PROJ version
8.2.0
EPSG Registry database version
v10.038 (2021-10-21)
GEOS version
3.10.0-CAPI-1.16.0
SQLite version
3.35.2
PDAL version
2.3.0
PostgreSQL client version
13.0
SpatiaLite version
5.0.1
QWT version
6.1.3
QScintilla2 version
2.11.5
OS version
Windows 10 Version 2009

Active Python plugins
BitFlagRenderer
0.4.20200817T093838.master
changeDataSource
3.1
DataPlotly
3.8.1
ee_plugin
0.0.4
force4qgis
1.0.1
InvisibleLayersAndGroups
2.1
rasterdataplotting
1.6.3
rastertimeseriesmanager
1.8
timeseriesviewerplugin
1.17.20210312T143004.master
zoomview
1.1.1
db_manager
0.1.20
grassprovider
2.12.99
MetaSearch
0.3.5
processing
2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

No response

@janzandr janzandr added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jan 31, 2022
@janzandr
Copy link
Author

Also note that GDAL can read raster of such size without a problem:

>>>iface.activeLayer().width()
65000
>>>iface.activeLayer().height()
46000
>>>gdal.Open(iface.activeLayer().source()).ReadAsArray().shape
(46000, 65000)

@jakimowb
Copy link
Contributor

jakimowb commented Jan 31, 2022

I can confirm this for OSGeo4W QGIS master. During initialization of the QgsRasterBlock the requested size_t = 6500000000 is too large and leads to long( size ) < 0 in *qgsMalloc( size_t size ).

void *qgsMalloc( size_t size )
{
  if ( size == 0 || long( size ) < 0 )
  {
    QgsDebugMsg( QStringLiteral( "Negative or zero size %1." ).arg( size ) );
    return nullptr;
  }
  void *p = malloc( size );
  if ( !p )
  {
    QgsDebugMsg( QStringLiteral( "Allocation of %1 bytes failed." ).arg( size ) );
  }
  return p;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API Rasters Related to general raster layer handling (not specific data formats)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants