Skip to content

Commit

Permalink
[gdal_rasterize] Fix crash with no options after argparser (#10770) (…
Browse files Browse the repository at this point in the history
…master only)

Fixes #10767
Followup #10741
  • Loading branch information
elpaso authored Sep 11, 2024
1 parent 1e48b77 commit 5999d8b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/gdal_rasterize_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,11 @@ GDALRasterizeOptionsNew(char **papszArgv,
if (!psOptions->osFormat.empty())
psOptionsForBinary->osFormat = psOptions->osFormat;
}
else if (psOptions->adfBurnValues.empty() &&
psOptions->osBurnAttribute.empty() && !psOptions->b3D)
{
psOptions->adfBurnValues.push_back(255);
}
}
catch (const std::exception &e)
{
Expand Down
34 changes: 34 additions & 0 deletions autotest/utilities/test_gdal_rasterize_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,3 +792,37 @@ def test_gdal_rasterize_lib_dict_arguments():
ind = opt.index("-co")

assert opt[ind : ind + 4] == ["-co", "COMPRESS=DEFLATE", "-co", "LEVEL=4"]


###############################################################################
# Test doesn't crash without options


def test_gdal_rasterize_no_options(tmp_vsimem):
"""Test doesn't crash without options"""

gdal.FileFromMemBuffer(
tmp_vsimem / "test.json",
r"""{
"type": "FeatureCollection",
"name": "test",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::4326" } },
"features": [
{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0, 0 ], [ 0, 1 ], [ 1, 1 ], [ 1, 0 ], [ 0, 0 ] ] ] } }
]
}""",
)

# Open the dataset
ds = gdal.OpenEx(tmp_vsimem / "test.json", gdal.OF_VECTOR)
assert ds

# Create a raster to rasterize into.
target_ds = gdal.GetDriverByName("GTiff").Create(
tmp_vsimem / "out.tif", 10, 10, 1, gdal.GDT_Byte
)

assert target_ds

# Call rasterize
ds = gdal.Rasterize(target_ds, ds)

0 comments on commit 5999d8b

Please sign in to comment.