From 31e495c7dab696d895232bc95711f5f323044492 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Wed, 22 Apr 2026 23:03:52 -0700 Subject: [PATCH] fix(utilities): reject empty sourceDS in BuildVRT/Warp/VectorTranslate BuildVRT, Warp, and VectorTranslate each construct srcDS from a caller-supplied []Dataset and then unconditionally take the address of srcDS[0] to pass to the GDAL C API. If sourceDS is empty (trivially reachable when callers build the slice dynamically and all entries get filtered out), &srcDS[0] panics with 'index out of range' before the Cgo call runs. Bail out early with a descriptive error naming the function. Happy path and non-empty inputs are unchanged. Refs lukeroth/gdal issue 112. Signed-off-by: SAY-5 --- utilities.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utilities.go b/utilities.go index 0c752a8..5c4f1ac 100644 --- a/utilities.go +++ b/utilities.go @@ -51,6 +51,9 @@ func Info(sourceDS Dataset, options []string) string { } func BuildVRT(dstDS string, sourceDS []Dataset, srcDSFilePath, options []string) (Dataset, error) { + if len(sourceDS) == 0 { + return Dataset{}, fmt.Errorf("BuildVRT: sourceDS must not be empty") + } if dstDS == "" { dstDS = "MEM:::" if !stringArrayContains(options, "-of") { @@ -103,6 +106,9 @@ func BuildVRT(dstDS string, sourceDS []Dataset, srcDSFilePath, options []string) } func Warp(dstDS string, destDS *Dataset, sourceDS []Dataset, options []string) (Dataset, error) { + if len(sourceDS) == 0 { + return Dataset{}, fmt.Errorf("Warp: sourceDS must not be empty") + } if dstDS == "" && destDS == nil { dstDS = "MEM:::" if !stringArrayContains(options, "-of") { @@ -176,6 +182,9 @@ func Translate(dstDS string, sourceDS Dataset, options []string) (Dataset, error } func VectorTranslate(dstDS string, sourceDS []Dataset, options []string) (Dataset, error) { + if len(sourceDS) == 0 { + return Dataset{}, fmt.Errorf("VectorTranslate: sourceDS must not be empty") + } if dstDS == "" { dstDS = "MEM:::" if !stringArrayContains(options, "-f") {