Skip to content

RasterIO crashes with panBandMap == NULL when using COG driver and Create() #14711

@rhijmans

Description

@rhijmans

What is the bug?

In GDAL 3.13.0, the COG driver gained Create capability (in addition to CreateCopy available in older versions). When writing data blocks with GDALRasterBand::RasterIO this crashes when using panBandMap = NULL while it works with panBandMap = {1}

It seems that python GDAL does not have this problem because the NULL is replaced by the band numbers.

Steps to reproduce the issue

#include <cstdio>
#include <vector>
#include <gdal.h>
#include <gdal_priv.h>

int main() {
    GDALAllRegister();
    GDALDriver* drv = GetGDALDriverManager()->GetDriverByName("COG");
    GDALDataset* ds = drv->Create("./cog_crash.tif", 95, 90, 1, GDT_Int16, nullptr);
    std::vector<int16_t> buf(95 * 90, 0);
    std::printf("RasterIO\n");
    ds->RasterIO(GF_Write,  0, 0, 95, 90, buf.data(), 95, 90, GDT_Int16, 1,         
                 nullptr,   // panBandMap == NULL : the problem
                 0, 0, 0, nullptr);
    std::printf("never reached\n");
    GDALClose(ds);
    return 0;
}

Versions and provenance

GDAL 3.13.0 with R/terra in rocker/r-base docker Debian container

Additional context

The problem was reported here and then here

Metadata

Metadata

Assignees

Labels

not for AI loversSee https://gdal.org/en/stable/community/ai_tool_policy.html

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions