Skip to content

Commit 8b117d6

Browse files
committed
Use external gdalinfo -checksum call to verify raster checksum
This avoids a segfault during GDAL checksum killing the entire python process.
1 parent e9c6dbb commit 8b117d6

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

batch_check_setsm.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919
import os
2020
import re
21+
import shlex
2122
import shutil
2223
import subprocess
2324
import sys
@@ -2059,19 +2060,28 @@ def check_rasters(raster_ffiles, checkfile, args):
20592060
"All bands will be checked for valid SETSM data range."
20602061
]))
20612062

2063+
if args.get(ARGSTR_CHECK_METHOD) == ARGCHO_CHECK_METHOD_CHECKSUM:
2064+
cmd = "gdalinfo -checksum {}".format(raster_ffile)
2065+
LOGGER.debug("Running checksum with the following command:\n{}".format(cmd))
2066+
proc = subprocess.run(shlex.split(cmd), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
2067+
if proc.returncode != 0:
2068+
errmsg_print_and_list(errmsg_list,
2069+
"'gdalinfo -checksum' failure with return code {}".format(proc.returncode))
2070+
raise RasterFileReadError()
2071+
20622072
for band_index in range(num_bands):
20632073
band_num = band_index + 1
20642074
band = ds.GetRasterBand(band_num)
20652075
LOGGER.debug("Processing Band {}".format(band_num))
20662076

2067-
if args.get(ARGSTR_CHECK_METHOD) == ARGCHO_CHECK_METHOD_CHECKSUM:
2068-
try:
2069-
LOGGER.debug("Doing checksum")
2070-
checksum = band.Checksum()
2071-
LOGGER.debug("Checksum succeeded: {}".format(checksum))
2072-
except RuntimeError as e:
2073-
errmsg_print_and_list(errmsg_list,
2074-
"Band {} checksum error: {}".format(band_num, e))
2077+
# if args.get(ARGSTR_CHECK_METHOD) == ARGCHO_CHECK_METHOD_CHECKSUM:
2078+
# try:
2079+
# LOGGER.debug("Doing checksum")
2080+
# checksum = band.Checksum()
2081+
# LOGGER.debug("Checksum succeeded: {}".format(checksum))
2082+
# except RuntimeError as e:
2083+
# errmsg_print_and_list(errmsg_list,
2084+
# "Band {} checksum error: {}".format(band_num, e))
20752085

20762086
if args.get(ARGSTR_CHECK_METHOD) == ARGCHO_CHECK_METHOD_READ or setsm_suffix is not None:
20772087
try:

0 commit comments

Comments
 (0)