From 2d1c9888ee92ec1de330e2f23c2aa0848b1c9657 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 20 Feb 2024 10:11:57 +0100 Subject: [PATCH] Python bindings: gdal.Translate()/gdal.Warp()/etc.: make sure not to modify provided options[] array (fixes #9259) --- swig/include/python/gdal_python.i | 42 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/swig/include/python/gdal_python.i b/swig/include/python/gdal_python.i index dd7cc86729f5..f38de0f718e4 100644 --- a/swig/include/python/gdal_python.i +++ b/swig/include/python/gdal_python.i @@ -2011,7 +2011,8 @@ def InfoOptions(options=None, format='text', deserialize=True, if '-json' in new_options: format = 'json' else: - new_options = options + import copy + new_options = copy.copy(options) if format == 'json': new_options += ['-json'] elif format != "text": @@ -2130,7 +2131,8 @@ def VectorInfoOptions(options=None, if '-json' in new_options: format = 'json' else: - new_options = options + import copy + new_options = copy.copy(options) if format == 'json': new_options += ['-json'] elif format != "text": @@ -2207,7 +2209,8 @@ def MultiDimInfoOptions(options=None, detailed=False, array=None, arrayoptions=N if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if detailed: new_options += ['-detailed'] if array: @@ -2367,7 +2370,8 @@ def TranslateOptions(options=None, format=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-of', format] if outputType != gdalconst.GDT_Unknown: @@ -2633,7 +2637,8 @@ def WarpOptions(options=None, format=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if srcBands: for b in srcBands: new_options += ['-srcband', str(b)] @@ -2979,7 +2984,8 @@ def VectorTranslateOptions(options=None, format=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-f', format] if srcSRS is not None: @@ -3248,7 +3254,8 @@ def DEMProcessingOptions(options=None, colorFilename=None, format=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-of', format] if creationOptions is not None: @@ -3380,7 +3387,8 @@ def NearblackOptions(options=None, format=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-of', format] if creationOptions is not None: @@ -3525,7 +3533,8 @@ def GridOptions(options=None, format=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-of', format] if outputType != gdalconst.GDT_Unknown: @@ -3692,7 +3701,8 @@ def RasterizeOptions(options=None, format=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-of', format] if outputType != gdalconst.GDT_Unknown: @@ -3881,7 +3891,8 @@ def FootprintOptions(options=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-of', format] if bands is not None: @@ -4106,7 +4117,8 @@ def BuildVRTOptions(options=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if resolution is not None: new_options += ['-resolution', str(resolution)] if outputBounds is not None: @@ -4278,7 +4290,8 @@ def TileIndexOptions(options=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if overwrite: new_options += ['-overwrite'] if recursive: @@ -4434,7 +4447,8 @@ def MultiDimTranslateOptions(options=None, format=None, creationOptions=None, if isinstance(options, str): new_options = ParseCommandLine(options) else: - new_options = options + import copy + new_options = copy.copy(options) if format is not None: new_options += ['-of', format] if creationOptions is not None: