USDAForestService / gdalraster

R Bindings to GDAL (Geospatial Data Abstraction Library)
https://usdaforestservice.github.io/gdalraster/
Other
41 stars 7 forks source link

crash on get-feature after all iterated #539

Closed mdsumner closed 6 days ago

mdsumner commented 1 week ago

this in current main dd5bfe1ba4cdd121ac5bde728ded71feb3305f2e

library(gdalraster)

dsn <- system.file("extdata/ynp_fires_1984_2022.gpkg", package = "gdalraster")
lyr <- new(GDALVector, dsn, "mtbs_perims")
lyr$setSelectedFields(c("incid_name", "ig_year", "OGR_GEOMETRY"))
lyr$setAttributeFilter("ig_year >= 2018")
for (i in seq_len(lyr$getFeatureCount() + 1 )) {
  print(i) 
  lyr$getNextFeature()   ## crash on 4
}

Same crash in #538

After fetch all we see messages.

## or after fetch all
library(gdalraster)

dsn <- system.file("extdata/ynp_fires_1984_2022.gpkg", package = "gdalraster")
lyr <- new(GDALVector, dsn, "mtbs_perims")
lyr$setAttributeFilter("ig_year >= 2018")
feat <- lyr$fetch(-1)
lyr$getNextFeature()  #messages
#ERROR 10: Pointer 'hFeat' is NULL in 'OGR_F_GetGeomFieldDefnRef'.
#ERROR 10: Pointer 'hDefn' is NULL in 'OGR_GFld_IsIgnored'.

(in #538 there are no messages)

Session info for current main.

R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3;  LAPACK version 3.9.0

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C

time zone: Australia/Hobart
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] gdalraster_1.11.1.9492

loaded via a namespace (and not attached):
[1] bit_4.5.0        compiler_4.4.1   cli_3.6.3        tools_4.4.1
[5] Rcpp_1.0.13      bit64_4.5.2      xml2_1.3.6       codetools_0.2-20
[9] rlang_1.1.4
ctoney commented 1 week ago

Thanks. It looks like the crash was introduced with setIgnoredFields()/setSelectedFields(), and there was not a test for reading past the end with ignored fields in use. It's easier to fix in #538 at this point due to changes there for attaching gis attributes. Commit 43d26b6 fixes the crash. A test with the code above that crashes was added in commit 8886d46.