r-spatial / sf

Simple Features for R
https://r-spatial.github.io/sf/
Other
1.34k stars 298 forks source link

sf::st_layers hanging R / bombing rstudio #1995

Closed dblodgett-usgs closed 1 year ago

dblodgett-usgs commented 2 years ago

When I try to sf::st_layers() on the attached gpkg, rstudio bombs. When I list from a terminal, I see:

> library(sf)
Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
> sf::st_layers("nav_06.gpkg")
        - 'VirtualXPath'        [XML Path Language - XPath]
Driver: GPKG
Available layers:
        layer_name geometry_type features fields
1 unassigned_gages         Point        6     16
2     split_events         Point       91      6
3      POIs_tmp_06         Point     2201     12

Reproduce with:

tmpf <- tempfile()
download.file("https://github.com/r-spatial/sf/files/9537145/nav_06.zip", tmpf)
utils::unzip(tmpf, "nav_06.gpkg")
sf::st_layers("nav_06.gpkg")
``` GEOS GDAL proj.4 "3.9.1" "3.4.3" "7.2.1" GDAL_with_GEOS USE_PROJ_H PROJ "true" "true" "7.2.1" ``` ``` R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044) Matrix products: default locale: [1] LC_COLLATE=English_United States.utf8 [2] LC_CTYPE=English_United States.utf8 [3] LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.utf8 attached base packages: [1] stats graphics grDevices utils datasets [6] methods base loaded via a namespace (and not attached): [1] compiler_4.2.1 tools_4.2.1 ``` Paste the output of your `sessionInfo()` and `sf::sf_extSoftVersion()`

nav_06.zip

edzer commented 2 years ago

Works without problems here, also in rstudio (ubuntu 20.04, RStudio 2022.07.1+554), also no issues when run under valgrind. What is your sessionInfo() after loading sf?

rsbivand commented 2 years ago

With Windows 10, R 4.2.1 RGui.exe and R.exe:

> sf::st_layers("nav_06.gpkg")
Driver: GPKG 
Available layers:
        layer_name geometry_type features fields             crs_name
1 unassigned_gages         Point        6     16 NAD83 / Conus Albers
2     split_events         Point       91      6 NAD83 / Conus Albers
3      POIs_tmp_06         Point     2201     12 NAD83 / Conus Albers

With freshly installed RStudio-2022.07.1-554.exe no problems. There were recent reports of odd errors in packages installed from the Rstudio mirror - try reinstalling sf outside Rstudio from another mirror?

dblodgett-usgs commented 2 years ago

I've been double checking all my installs. This is straight from an Rterm.exe under Cmder. Now sst_layers() just hangs. This is after a devtools::install_github("r-spatial/sf")

> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

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

loaded via a namespace (and not attached):
[1] compiler_4.2.1
> sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H
       "3.9.1"        "3.4.3"        "7.2.1"         "true"         "true"
          PROJ
       "7.2.1"
> sf::st_layers("nav_06.gpkg")
rsbivand commented 2 years ago

Does released sf have the same problem?

dblodgett-usgs commented 2 years ago

Yes. The output of sf::st_layers() below is just hung and unresponsive.

> library(sf)                                                                                             
Error in library(sf) : there is no package called 'sf'                                                    
> install.packages("sf")                                                                                  
Installing package into '---/R/win-library/4.2'                              
(as 'lib' is unspecified)                                                                                                      
trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.2/sf_1.0-8.zip'                             
Content type 'application/zip' length 25291244 bytes (24.1 MB)                                            
downloaded 24.1 MB                                                                                        

package 'sf' successfully unpacked and MD5 sums checked                                                   

The downloaded binary packages are in                                                                     
        ---\AppData\Local\Temp\1\Rtmpa2wXeQ\downloaded_packages                            
> library(sf)                                                                                             
Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE                                        
> sessionInfo()                                                                                           
R version 4.2.1 (2022-06-23 ucrt)                                                                         
Platform: x86_64-w64-mingw32/x64 (64-bit)                                                                 
Running under: Windows 10 x64 (build 19044)                                                               

Matrix products: default                                                                                  

locale:                                                                                                   
[1] LC_COLLATE=English_United States.utf8                                                                 
[2] LC_CTYPE=English_United States.utf8                                                                   
[3] LC_MONETARY=English_United States.utf8                                                                
[4] LC_NUMERIC=C                                                                                          
[5] LC_TIME=English_United States.utf8                                                                    

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

other attached packages:                                                                                  
[1] sf_1.0-8                                                                                              

loaded via a namespace (and not attached):                                                                
 [1] Rcpp_1.0.9         magrittr_2.0.3     units_0.8-0        tidyselect_1.1.2                            
 [5] R6_2.5.1           rlang_1.0.4        fansi_1.0.3        dplyr_1.0.9                                 
 [9] tools_4.2.1        grid_4.2.1         KernSmooth_2.23-20 utf8_1.2.2                                  
[13] cli_3.3.0          e1071_1.7-11       DBI_1.1.3          class_7.3-20                                
[17] assertthat_0.2.1   tibble_3.1.8       lifecycle_1.0.1    purrr_0.3.4                                 
[21] vctrs_0.4.1        glue_1.6.2         proxy_0.4-27       compiler_4.2.1                              
[25] pillar_1.8.1       generics_0.1.3     classInt_0.4-7     pkgconfig_2.0.3                             
> sf::st_layers("nav_06.gpkg")                                                                            
rsbivand commented 2 years ago

Long shot, re-install Rcpp from a CRAN mirror?

dblodgett-usgs commented 2 years ago

nope. I guess now's as good a time as any to reinstall all the things.

dblodgett-usgs commented 2 years ago

I've now completely uninstalled R and all my packages and upgraded rstudio. If I run this in a terminal, the R for Windows terminal front-end process hammers a CPU and cycles between ~500mb of memory used and 3500mb.

I'm going to step through the code that creates this and try and find what the hang up is.

dblodgett-usgs commented 2 years ago

Alright -- I've narrowed this down to its source. The issue is an attribute "uniqueID" that is causing the gpkg reader to hang. If I uncomment the last line, reprex hangs. If I run this in rstudio, it bombs rstudio.

While it is hung, the R for Windows process is hammering a CPU and eating between 200 and 4000MB of memory with this sawtooth pattern. Happy to do more debugging or dump some other logs if someone knows where to go looking for them.

I guess I'll stop using this "uniqueID" attribute for now. 😝

image

borked <- sf::read_sf('
{
    "type": "FeatureCollection",
    "name": "borked",
    "crs": {
        "type": "name",
        "properties": {
            "name": "urn:ogc:def:crs:EPSG::5070"
        }
    },
    "features": [
        {
            "type": "Feature",
            "properties": {
                "COMID": 19736669,
                "REACHCODE": "06010202003357",
                "REACH_meas": 22.451321717399999,
                "uniqueID": "03507000"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    1117044.368864378193393,
                    1445765.030222098575905
                ]
            }
        },
        {
            "type": "Feature",
            "properties": {
                "COMID": 19677981,
                "REACHCODE": "06020002000118",
                "REACH_meas": 61.4738,
                "uniqueID": "03554000"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    1072594.611272452631965,
                    1396990.093436731025577
                ]
            }
        }
    ]
}
')

sf::write_sf(borked, "borked.gpkg")

sf::write_sf(dplyr::rename(borked, ID = uniqueID), "works.gpkg")

sf::read_sf("works.gpkg")
#> Simple feature collection with 2 features and 4 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 1072595 ymin: 1396990 xmax: 1117044 ymax: 1445765
#> Projected CRS: NAD83 / Conus Albers
#> # A tibble: 2 × 5
#>      COMID REACHCODE      REACH_meas ID                    geom
#>      <int> <chr>               <dbl> <chr>          <POINT [m]>
#> 1 19736669 06010202003357       22.5 03507000 (1117044 1445765)
#> 2 19677981 06020002000118       61.5 03554000 (1072595 1396990)

# sf::read_sf("borked.gpkg")

sessionInfo()
#> R version 4.2.1 (2022-06-23 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9         compiler_4.2.1     pillar_1.8.1       highr_0.9         
#>  [5] class_7.3-20       tools_4.2.1        digest_0.6.29      evaluate_0.16     
#>  [9] lifecycle_1.0.2    tibble_3.1.8       pkgconfig_2.0.3    rlang_1.0.5       
#> [13] reprex_2.0.2       DBI_1.1.3          cli_3.4.0          rstudioapi_0.14   
#> [17] yaml_2.3.5         xfun_0.32          fastmap_1.1.0      e1071_1.7-11      
#> [21] withr_2.5.0        stringr_1.4.1      dplyr_1.0.10       knitr_1.40        
#> [25] generics_0.1.3     fs_1.5.2           vctrs_0.4.1        tidyselect_1.1.2  
#> [29] classInt_0.4-7     grid_4.2.1         glue_1.6.2         sf_1.0-8          
#> [33] R6_2.5.1           fansi_1.0.3        rmarkdown_2.16     purrr_0.3.4       
#> [37] magrittr_2.0.3     ellipsis_0.3.2     htmltools_0.5.3    units_0.8-0       
#> [41] KernSmooth_2.23-20 utf8_1.2.2         stringi_1.7.8      proxy_0.4-27

sf::sf_extSoftVersion()
#>           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
#>        "3.9.1"        "3.4.3"        "7.2.1"         "true"         "true" 
#>           PROJ 
#>        "7.2.1"

Created on 2022-09-09 with reprex v2.0.2

dblodgett-usgs commented 2 years ago

After some further testing, it's actually any attribute with "unique" in the name.

e.g. this causes it.

nc <- sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
nc <- dplyr::rename(nc, "cnty_unique_id" = CNTY_ID)
sf::write_sf(nc, "nc_test.gpkg")
sf::read_sf("nc_test.gpkg")
rsbivand commented 2 years ago

Very odd (Windows 10)

> nc <- sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
> nc <- dplyr::rename(nc, "cnty_unique_id" = CNTY_ID)
> sf::write_sf(nc, "nc_test.gpkg")
> sf::read_sf("nc_test.gpkg")
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS:  NAD27
# A tibble: 100 × 15
    AREA PERIMETER CNTY_ cnty_u…¹ NAME  FIPS  FIPSNO CRESS…² BIR74 SID74 NWBIR74
   <dbl>     <dbl> <dbl>    <dbl> <chr> <chr>  <dbl>   <int> <dbl> <dbl>   <dbl>
 1 0.114      1.44  1825     1825 Ashe  37009  37009       5  1091     1      10
 2 0.061      1.23  1827     1827 Alle… 37005  37005       3   487     0      10
 3 0.143      1.63  1828     1828 Surry 37171  37171      86  3188     5     208
 4 0.07       2.97  1831     1831 Curr… 37053  37053      27   508     1     123
 5 0.153      2.21  1832     1832 Nort… 37131  37131      66  1421     9    1066
 6 0.097      1.67  1833     1833 Hert… 37091  37091      46  1452     7     954
 7 0.062      1.55  1834     1834 Camd… 37029  37029      15   286     0     115
 8 0.091      1.28  1835     1835 Gates 37073  37073      37   420     0     254
 9 0.118      1.42  1836     1836 Warr… 37185  37185      93   968     4     748
10 0.124      1.43  1837     1837 Stok… 37169  37169      85  1612     1     160
# … with 90 more rows, 4 more variables: BIR79 <dbl>, SID79 <dbl>,
#   NWBIR79 <dbl>, geom <MULTIPOLYGON [°]>, and abbreviated variable names
#   ¹​cnty_unique_id, ²​CRESS_ID
# ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
> names(sf::read_sf("nc_test.gpkg"))
 [1] "AREA"           "PERIMETER"      "CNTY_"          "cnty_unique_id"
 [5] "NAME"           "FIPS"           "FIPSNO"         "CRESS_ID"
 [9] "BIR74"          "SID74"          "NWBIR74"        "BIR79"
[13] "SID79"          "NWBIR79"        "geom"
> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] C

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9         magrittr_2.0.3     units_0.8-0        tidyselect_1.1.2
 [5] R6_2.5.1           rlang_1.0.5        fansi_1.0.3        dplyr_1.0.10
 [9] tools_4.2.1        grid_4.2.1         KernSmooth_2.23-20 utf8_1.2.2
[13] cli_3.3.0          e1071_1.7-11       DBI_1.1.3          ellipsis_0.3.2
[17] class_7.3-20       tibble_3.1.8       lifecycle_1.0.2    sf_1.0-8
[21] purrr_0.3.4        vctrs_0.4.1        glue_1.6.2         proxy_0.4-27
[25] compiler_4.2.1     pillar_1.8.1       generics_0.1.3     classInt_0.4-7
[29] pkgconfig_2.0.3
rsbivand commented 2 years ago

Maybe also try terra:

> terra::vect("nc_test.gpkg")
 class       : SpatVector
 geometry    : polygons
 dimensions  : 100, 14  (geometries, attributes)
 extent      : -84.32385, -75.45698, 33.88199, 36.58965  (xmin, xmax, ymin, ymax)
 source      : nc_test.gpkg
 coord. ref. : lon/lat NAD27 (EPSG:4267)
 names       :  AREA PERIMETER CNTY_ cnty_unique_id      NAME  FIPS    FIPSNO
 type        : <num>     <num> <num>          <num>     <chr> <chr>     <num>
 values      : 0.114     1.442  1825           1825      Ashe 37009 3.701e+04
               0.061     1.231  1827           1827 Alleghany 37005   3.7e+04
               0.143      1.63  1828           1828     Surry 37171 3.717e+04
 CRESS_ID BIR74 SID74 (and 4 more)
    <int> <num> <num>
        5  1091     1
        3   487     0
       86  3188     5

which uses the same GDAL binary library.

rsbivand commented 2 years ago

And:

> sf::read_sf("works.gpkg")
Simple feature collection with 2 features and 4 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 1072595 ymin: 1396990 xmax: 1117044 ymax: 1445765
Projected CRS: NAD83 / Conus Albers
# A tibble: 2 × 5
     COMID REACHCODE      REACH_meas ID                    geom
     <int> <chr>               <dbl> <chr>          <POINT [m]>
1 19736669 06010202003357       22.5 03507000 (1117044 1445765)
2 19677981 06020002000118       61.5 03554000 (1072595 1396990)
> sf::read_sf("borked.gpkg")
Simple feature collection with 2 features and 4 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 1072595 ymin: 1396990 xmax: 1117044 ymax: 1445765
Projected CRS: NAD83 / Conus Albers
# A tibble: 2 × 5
     COMID REACHCODE      REACH_meas uniqueID              geom
     <int> <chr>               <dbl> <chr>          <POINT [m]>
1 19736669 06010202003357       22.5 03507000 (1117044 1445765)
2 19677981 06020002000118       61.5 03554000 (1072595 1396990)
dblodgett-usgs commented 2 years ago

terra::vect has the same behavior. So something in here?

> sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
       "3.9.1"        "3.4.3"        "7.2.1"         "true"         "true"        "7.2.1" 
edzer commented 2 years ago

terra copied some C++ code from sf for reading/writing OGR data, so it might be in there, or it is in GDAL (but I'm running GDAL 3.4.3 too) or in libsqlite3 (which GDAL uses to write/read GPKG), or in the windows build train (new in R 4.2: ucrt). I really have no clue - the weird thing is that rstudio triggers it, regular R doesn't, and only on windows. Can you reproduce it in rstudio on Windows, @rsbivand ?

rsbivand commented 2 years ago

No, nothing with a freshly installed rstudio with the original reprex. My Windows 10 version is the same too. Is any package not a CRAN binary?

dblodgett-usgs commented 2 years ago

No... I reinstalled R, Rstudio, and my entire library with devtools yesterday. I'll do a little more snooping here.

rsbivand commented 2 years ago

Do you know which mirror was used?

dblodgett-usgs commented 2 years ago

The default cloud one. For the record, I have installed sf with a native build (with rstudio package build tools) and it's still happening. Trying to get into my windows crash dumps to see if anything is emitted of use.

rsbivand commented 2 years ago

By native build, do you mean the released Rtools42? Please simplify by avoiding any Rstudio packages in any source builds, use only the very simplest route. My installs for which no errors occur are just standard CRAN binary installs, though I have Rtools42, and even (not now) test versions of MXE-built libgdal.a testing updated drivers. I have a feeling that somewhere you have a component built with a non-standard build chain.

rsbivand commented 2 years ago

@edzer : borked.gpkg and nc_test.gpkg OK also in rstudio.

dblodgett-usgs commented 2 years ago

OK -- I think this might be something? This is generated by looking at the crash dump in WinDbg.

See the lines with stuff like the following out in the middle of the stack: sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x6a9d4

From sf:

``` EXCEPTION_RECORD: (.exr -1) ExceptionAddress: 00007fff3f8e1208 (ucrtbase!invoke_watson+0x0000000000000018) ExceptionCode: c0000409 (Security check failure or stack buffer overrun) ExceptionFlags: 00000001 NumberParameters: 1 Parameter[0]: 0000000000000005 Subcode: 0x5 FAST_FAIL_INVALID_ARG PROCESS_NAME: rsession-utf8.exe ERROR_CODE: (NTSTATUS) 0xc0000409 - The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application. EXCEPTION_CODE_STR: c0000409 EXCEPTION_PARAMETER1: 0000000000000005 FAULTING_THREAD: 00002efc STACK_TEXT: 00000004`a77f2be0 00007fff`3f8924b1 : 00000000`00000459 00000004`a77f2e50 00000000`80000000 00007fff`3f883a81 : ucrtbase!invoke_watson+0x18 00000004`a77f2c10 00007fff`3f892379 : 00000000`7fffffff 00007fff`3f883496 00000000`00000459 00000000`80000000 : ucrtbase!_invalid_parameter+0x12d 00000004`a77f2c50 00007fff`3f897ff7 : 00000000`7fffffff 00000000`80000000 00000004`a77f2e50 00007fff`3f87fde6 : ucrtbase!invalid_parameter_noinfo+0x9 00000004`a77f2c90 00007ffe`aa961e3b : 00000000`80000000 00000004`a77f2e50 00000004`a77f2d70 00000004`a77f2e30 : ucrtbase!strxfrm_l+0x57 00000004`a77f2d10 00007ffe`aa961fef : 000001d4`3e6fa761 00000004`a77f2fd9 000001d4`3e6fa760 000001d4`3e6fa761 : sf!ZNKSt5ctypeIcE8do_widenEc+0x2079b 00000004`a77f2dd0 00007ffe`aa960fd4 : 00000004`a77f2e20 000001d4`3e6fa760 000001d4`3e6fa761 00000004`a77f2e47 : sf!ZNKSt5ctypeIcE8do_widenEc+0x2094f 00000004`a77f2e00 00007ffe`aa960950 : 00000004`a77f2f40 000001d4`49b5edf8 000001d4`3e6fa760 000001d4`3e6fa761 : sf!ZNKSt5ctypeIcE8do_widenEc+0x1f934 00000004`a77f2e70 00007ffe`aad51098 : 00000004`a77f2f40 000001d4`49b5edf8 00000004`a77f2fd8 00000004`a77f2fd9 : sf!ZNKSt5ctypeIcE8do_widenEc+0x1f2b0 00000004`a77f2ee0 00007ffe`aa997aec : 00000004`a77f2fd0 00007ffe`aab132af 00000000`0000001f 00000004`a77f314c : sf!ZTv0_n24_N4Rcpp8RostreamILb1EED1Ev+0x3b18 00000004`a77f2fb0 00007ffe`aac93818 : 00000004`a77f30d0 00000004`a77f3180 00000000`0000007f 00000000`00000000 : sf!ZNKSt5ctypeIcE8do_widenEc+0x5644c 00000004`a77f2ff0 00007ffe`aac93cb5 : 00000004`a77f30d0 00000000`00000000 00000000`00000000 00000004`00000020 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x6c038 00000004`a77f3050 00007ffe`aac9f693 : 00000004`a77f30d0 00000004`a77f3640 000001d4`49b5ed00 000001d4`45b82ba0 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x6c4d5 00000004`a77f30b0 00007ffe`aac9fcb4 : 00000004`a77f3530 00007ffe`00000008 00000004`a77f32a0 00007ffe`aab0fd5e : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x77eb3 00000004`a77f3260 00007ffe`aac9fec9 : 00000004`a77f3530 000001d4`462c4650 000001d4`462c4650 000001d4`462c4650 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x784d4 00000004`a77f32f0 00007ffe`aac9cd29 : 00000004`a77f3530 00007ffe`aab0fd08 00000004`a77f3660 00000000`00000000 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x786e9 00000004`a77f3320 00007ffe`aac9cd46 : 00000004`a77f3530 00000004`a77f3530 00000004`a77f33d0 00007ffe`aac9abc5 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x75549 00000004`a77f3390 00007ffe`aac9ce09 : 00000004`a77f3530 00000000`00000000 00000004`a77f3440 00007ffe`aa938c95 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x75566 00000004`a77f3400 00007ffe`aaca00ac : 00000004`a77f3530 000001d4`00000000 00000004`00000000 00000000`00000011 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x75629 00000004`a77f3480 00007ffe`aac921b4 : 00000004`a77f3530 00007ffe`aaf1f7d8 00007ffe`aaf1f80d 00007ffe`abce8de8 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x788cc 00000004`a77f3500 00007ffe`aabc935b : 00007ffe`abce8df0 00007ffe`aaf1f7d8 00007ffe`aaf1f80d 00007ffe`abce8de8 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x6a9d4 00000004`a77f36e0 00007ffe`aabc9292 : 00007ffe`abce8de0 00007ffe`aaf1f7d8 00007ffe`aaf1f80d 00000004`a77f3778 : sf!ZNSt6vectorIySaIyEE17_M_realloc_insertIJyEEEvN9__gnu_cxx17__normal_iteratorIPyS1_EEDpOT_+0x5edb 00000004`a77f3740 00007ffe`aabc9221 : 00007ffe`abce8de0 00007ffe`aaf1f7d8 00007ffe`aaf1f80d 000001d4`00000001 : sf!ZNSt6vectorIySaIyEE17_M_realloc_insertIJyEEEvN9__gnu_cxx17__normal_iteratorIPyS1_EEDpOT_+0x5e12 00000004`a77f37a0 00007ffe`a8ffe8da : 00007ffe`abce8de0 00007ffe`aaf1f7d8 000001d4`00000001 00000000`00000001 : sf!ZNSt6vectorIySaIyEE17_M_realloc_insertIJyEEEvN9__gnu_cxx17__normal_iteratorIPyS1_EEDpOT_+0x5da1 00000004`a77f37d0 00007ffe`a8f9a925 : 00000004`a77f3e80 000001d4`3e444788 000001d4`3e6fa7f0 00000000`00000001 : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x6d261a 00000004`a77f3c10 00007ffe`a8f99bfc : 000001d4`49644650 00000000`00000013 00000004`00000013 00000000`00000013 : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x66e665 00000004`a77f4020 00007ffe`a8fa0370 : 000001d4`49644650 00007ffe`aaafa700 00000000`0000018c 00000004`a77f40c0 : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x66d93c 00000004`a77f4050 00007ffe`a88db493 : 000001d4`49644650 010001d4`00000001 000001d4`3e76c350 00007fff`000001ad : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x6740b0 00000004`a77f41e0 00007ffe`a88e12e7 : 00000004`a77f48f0 000001d4`49644650 00000000`00000000 000001d4`3e6fa7d0 : sf!Z16sf_from_ogrlayerP8OGRLayerbbN4Rcpp6VectorILi14ENS1_15PreserveStorageEEENS2_ILi16ES3_EEb+0x63 00000004`a77f45b0 00007ffe`a88c2c0d : 00000004`a77f48f0 00000004`a77f47f0 000001d4`40492db0 000001d4`3a263198 : sf!Z12CPL_read_ogrN4Rcpp6VectorILi16ENS_15PreserveStorageEEES2_S2_S2_bNS0_ILi14ES1_EES2_S2_S2_bbbbi+0x8b7 00000004`a77f4740 00007ffe`b3aa6d6c : 000001d4`4433a7c0 000001d4`427da170 000001d4`427dade8 000001d4`3a2632b0 : sf!sf_CPL_read_ogr+0x20d 00000004`a77f4960 00007ffe`b3aa776d : 000001d4`3c2ab190 00000004`a77f4c08 00000004`a77f4c10 00000004`a77f4e40 : R!Rf_NewFrameConfirm+0x840c 00000004`a77f4b90 00007ffe`b3aebdc4 : 000001d4`43d30810 000001d4`3a223320 000001d4`3c2ab270 000001d4`3d6816e8 : R!Rf_NewFrameConfirm+0x8e0d 00000004`a77f5290 00007ffe`b3b05071 : 000001d4`43d30768 000001d4`3c2abd98 00000000`00000000 00000001`00000000 : R!R_initAssignSymbols+0x4814 00000004`a77f67e0 00007ffe`b3b0a6ec : 00000000`00000001 000001d4`401220f8 00000000`00000025 00000000`00000158 : R!R_initAssignSymbols+0x1dac1 00000004`a77f6a80 00007ffe`b3b0bafa : 000001d4`43d27fd0 000001d4`3c2abd98 000001d4`43d27ba8 000001d4`3c2af798 : R!R_cmpfun1+0x389c 00000004`a77f6e10 00007ffe`b3af9964 : 000001d4`3d19d6e0 000001d4`3a218dd0 000001d4`3c2ab4a0 00000000`412c7d10 : R!Rf_applyClosure+0x1aa 00000004`a77f6ea0 00007ffe`b3b05071 : 000001d4`43d26da8 000001d4`3c2af798 00007ffe`b5c612d0 000001d4`3c2b5db0 : R!R_initAssignSymbols+0x123b4 00000004`a77f83f0 00007ffe`b3b0a6ec : 000001d4`3a263198 00000000`00000000 00000000`00000000 00000000`00000000 : R!R_initAssignSymbols+0x1dac1 00000004`a77f8690 00007ffe`b3b0bafa : 000001d4`3c2af338 000001d4`3c2af798 00007ffe`b5c61078 000001d4`3c2af028 : R!R_cmpfun1+0x389c 00000004`a77f8a20 00007ffe`b3b4937a : 00007ffe`b5c61078 00007ffe`b3a52d79 000001d4`3c2aebc8 00007ffe`b3b471d9 : R!Rf_applyClosure+0x1aa 00000004`a77f8ab0 00007ffe`b3b498ec : 000001d4`3a2632b0 000001d4`43d3c0e0 000001d4`3a240f68 00007ffe`b5c612f8 : R!R_has_methods_attached+0x37a 00000004`a77f8b30 00007ffe`b3b49be9 : 000001d4`40108858 000001d4`3dab0308 000001d4`3dab02d0 00007ffe`b3beed0a : R!R_has_methods_attached+0x8ec 00000004`a77f8be0 00007ffe`b3aeb7a1 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : R!R_has_methods_attached+0xbe9 00000004`a77f9090 00007ffe`b3b05071 : 000001d4`3dab0298 000001d4`3c2af028 000001d4`3a0a02b4 00007fff`420bb86b : R!R_initAssignSymbols+0x41f1 00000004`a77fa5e0 00007ffe`b3b0a6ec : 00000000`00000001 00007fff`3f87f05b 000001d4`3e718f90 00000004`a77fabd0 : R!R_initAssignSymbols+0x1dac1 00000004`a77fa880 00007ffe`b3b0bafa : 000001d4`3d447380 000001d4`3c2af028 00007ffe`b5c612c8 000001d4`3c2aea78 : R!R_cmpfun1+0x389c 00000004`a77fac10 00007ffe`b3af9964 : 00000002`00000002 00000001`0000000d 000001d4`3c2aebc8 00000017`00000001 : R!Rf_applyClosure+0x1aa 00000004`a77faca0 00007ffe`b3b05071 : 000001d4`3d4472a0 000001d4`3c2aea78 00000000`00000000 00007fff`420bb86b : R!R_initAssignSymbols+0x123b4 00000004`a77fc1f0 00007ffe`b3b0a6ec : 00000000`0221003e 00000000`00000028 000001d4`3e6e6c80 00000000`00000000 : R!R_initAssignSymbols+0x1dac1 00000004`a77fc490 00007ffe`b3b0bafa : 000001d4`3c2ae7a0 000001d4`3c2aea78 000001d4`45b80fb0 000001d4`3a244248 : R!R_cmpfun1+0x389c 00000004`a77fc820 00007ffe`b3b051b3 : 000001d4`3e6e6c80 00000000`0000021b 000001d4`3c2ae928 000001d4`3e7147e0 : R!Rf_applyClosure+0x1aa 00000004`a77fc8b0 00007ffe`b3b337bd : 2f3d4843`52415f52 00000000`00343678 00000004`a77fcd00 00007fff`420c219c : R!R_initAssignSymbols+0x1dc03 00000004`a77fcb50 00007ffe`b3b33b78 : 00000000`00000000 000001d4`3a17e400 0000000f`00000000 000001d4`3a0a1f80 : R!Rf_ReplIteration+0x23d 00000004`a77fcbb0 00007ffe`b3b33c12 : 00000000`00000002 000001d4`3a1e7ff0 00000000`00000001 00000000`00000000 : R!Rf_ReplIteration+0x5f8 00000004`a77fdc30 00007ff7`7fd313ce : 00000000`00000000 00000000`00000000 00000000`00000002 000001d4`3a1df450 : R!run_Rmainloop+0x52 00000004`a77fdc60 00007ff7`7fd2a8ad : 000001d4`3a1ef201 00000000`00000001 00000004`a77fe070 00000004`a77fdf90 : rsession_utf8+0xd113ce 00000004`a77fde90 00007ff7`7f2da9e0 : 00000000`00000000 00000004`a77ffb50 00000000`00000000 00007ff7`8085a8d0 : rsession_utf8+0xd0a8ad 00000004`a77fe310 00007ff7`800f9750 : 00000000`00000000 00000000`00000000 000001d4`3a182b60 00000000`00000000 : rsession_utf8+0x2ba9e0 00000004`a77ffcd0 00007fff`41567034 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : rsession_utf8+0x10d9750 00000004`a77ffd10 00007fff`420e2651 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x14 00000004`a77ffd40 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21 STACK_COMMAND: ~0s ; .cxr ; kb SYMBOL_NAME: ucrtbase!invoke_watson+18 MODULE_NAME: ucrtbase IMAGE_NAME: ucrtbase.dll FAILURE_BUCKET_ID: FAIL_FAST_INVALID_ARG_c0000409_ucrtbase.dll!invoke_watson OS_VERSION: 10.0.19041.1 BUILDLAB_STR: vb_release OSPLATFORM_TYPE: x64 OSNAME: Windows 10 IMAGE_VERSION: 10.0.19041.789 FAILURE_ID_HASH: {ff968da7-5196-0e9d-7c2c-c6a2c196fc27} Followup: MachineOwner --------- ```

From terra:

``` EXCEPTION_RECORD: (.exr -1) ExceptionAddress: 00007fff3f8e1208 (ucrtbase!invoke_watson+0x0000000000000018) ExceptionCode: c0000409 (Security check failure or stack buffer overrun) ExceptionFlags: 00000001 NumberParameters: 1 Parameter[0]: 0000000000000005 Subcode: 0x5 FAST_FAIL_INVALID_ARG PROCESS_NAME: rsession-utf8.exe ERROR_CODE: (NTSTATUS) 0xc0000409 - The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application. EXCEPTION_CODE_STR: c0000409 EXCEPTION_PARAMETER1: 0000000000000005 FAULTING_THREAD: 0000097c STACK_TEXT: 000000e6`101f4a80 00007fff`3f8924b1 : 00000000`00000459 000000e6`101f4cf0 00000000`80000000 00007fff`3f883a81 : ucrtbase!invoke_watson+0x18 000000e6`101f4ab0 00007fff`3f892379 : 00000000`7fffffff 00007fff`3f883496 00000000`00000459 00000000`80000000 : ucrtbase!_invalid_parameter+0x12d 000000e6`101f4af0 00007fff`3f897ff7 : 00000000`7fffffff 00000000`80000000 000000e6`101f4cf0 00007fff`3f87fde6 : ucrtbase!invalid_parameter_noinfo+0x9 000000e6`101f4b30 00007ffe`91b1156b : 00000000`80000000 000000e6`101f4cf0 000000e6`101f4c10 000000e6`101f4cd0 : ucrtbase!strxfrm_l+0x57 000000e6`101f4bb0 00007ffe`91b1171f : 00000219`8ee02521 000000e6`101f4e79 00000219`8ee02520 00000219`8ee02521 : terra!ZNKSt5ctypeIcE8do_widenEc+0x2008b 000000e6`101f4c70 00007ffe`91b108f4 : 000000e6`101f4cc0 00000219`8ee02520 00000219`8ee02521 000000e6`101f4ce7 : terra!ZNKSt5ctypeIcE8do_widenEc+0x2023f 000000e6`101f4ca0 00007ffe`91b10270 : 000000e6`101f4de0 00000219`8e0ebab8 00000219`8ee02520 00000219`8ee02521 : terra!ZNKSt5ctypeIcE8do_widenEc+0x1f414 000000e6`101f4d10 00007ffe`91efb1e8 : 000000e6`101f4de0 00000219`8e0ebab8 000000e6`101f4e78 000000e6`101f4e79 : terra!ZNKSt5ctypeIcE8do_widenEc+0x1ed90 000000e6`101f4d80 00007ffe`91b46fac : 000000e6`101f4e70 00007ffe`91cbd2af 00000000`0000001f 000000e6`101f4fec : terra!ZTv0_n24_N4Rcpp8RostreamILb1EED1Ev+0x3a58 000000e6`101f4e50 00007ffe`91e40528 : 000000e6`101f4f70 000000e6`101f4f80 00000000`0000007f 00000000`00000000 : terra!ZNKSt5ctypeIcE8do_widenEc+0x55acc 000000e6`101f4e90 00007ffe`91e409c5 : 000000e6`101f4f70 00000000`00000000 00000000`00000000 000000e6`00000020 : terra!ZNSt8_Rb_treeIddSt9_IdentityIdESt4lessIdESaIdEE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIdERKd+0x2d1a8 000000e6`101f4ef0 00007ffe`91e4c1e3 : 000000e6`101f4f70 000000e6`101f54e0 00000219`8e0eba00 00000219`9a62ff20 : terra!ZNSt8_Rb_treeIddSt9_IdentityIdESt4lessIdESaIdEE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIdERKd+0x2d645 000000e6`101f4f50 00007ffe`91e4c804 : 000000e6`101f53d0 00007ffe`00000008 000000e6`101f5140 00007ffe`91cb9e1e : terra!ZNSt8__detail18__to_chars_10_implIyEEvPcjT_+0x6973 000000e6`101f5100 00007ffe`91e4ca19 : 000000e6`101f53d0 00000219`8e92b910 00000219`8e92b910 00000219`8e92b910 : terra!ZNSt8__detail18__to_chars_10_implIyEEvPcjT_+0x6f94 000000e6`101f5190 00007ffe`91e49879 : 000000e6`101f53d0 00007ffe`91cb9dc8 000000e6`101f5500 00000000`00000000 : terra!ZNSt8__detail18__to_chars_10_implIyEEvPcjT_+0x71a9 000000e6`101f51c0 00007ffe`91e49896 : 000000e6`101f53d0 000000e6`101f53d0 000000e6`101f5270 00007ffe`91e47715 : terra!ZNSt8__detail18__to_chars_10_implIyEEvPcjT_+0x4009 000000e6`101f5230 00007ffe`91e49959 : 000000e6`101f53d0 00000000`00000000 000000e6`101f52e0 00007ffe`91ae9095 : terra!ZNSt8__detail18__to_chars_10_implIyEEvPcjT_+0x4026 000000e6`101f52a0 00007ffe`91e4cbfc : 000000e6`101f53d0 00000219`00000000 000000e6`00000000 00000000`00000011 : terra!ZNSt8__detail18__to_chars_10_implIyEEvPcjT_+0x40e9 000000e6`101f5320 00007ffe`91e3eec4 : 000000e6`101f53d0 00007ffe`920b7778 00007ffe`920b77ad 00007ffe`92ecb988 : terra!ZNSt8__detail18__to_chars_10_implIyEEvPcjT_+0x738c 000000e6`101f53a0 00007ffe`91d79b2b : 00007ffe`92ecb990 00007ffe`920b7778 00007ffe`920b77ad 00007ffe`92ecb988 : terra!ZNSt8_Rb_treeIddSt9_IdentityIdESt4lessIdESaIdEE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIdERKd+0x2bb44 000000e6`101f5580 00007ffe`91d79a62 : 00007ffe`92ecb980 00007ffe`920b7778 00007ffe`920b77ad 000000e6`101f5618 : terra!ZNSt6vectorIySaIyEE7reserveEy+0x48ab 000000e6`101f55e0 00007ffe`91d799f1 : 00007ffe`92ecb980 00007ffe`920b7778 00007ffe`920b77ad 00000219`00000001 : terra!ZNSt6vectorIySaIyEE7reserveEy+0x47e2 000000e6`101f5640 00007ffe`9004bcaa : 00007ffe`92ecb980 00007ffe`920b7778 00000219`00000001 00000000`00000001 : terra!ZNSt6vectorIySaIyEE7reserveEy+0x4771 000000e6`101f5670 00007ffe`8ffe7cf5 : 000000e6`101f5d20 00000219`8e861278 00000219`8ee02530 000000e6`101f6090 : terra!ZN13SpatDataFrame9write_dbfENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbR11SpatOptions+0x5b022a 000000e6`101f5ab0 00007ffe`8ffe6fcc : 00000219`9adc7890 00000000`00000000 00000000`00000000 000000e6`101f5f90 : terra!ZN13SpatDataFrame9write_dbfENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbR11SpatOptions+0x54c275 000000e6`101f5ec0 00007ffe`8fff8488 : 00000219`9adc7890 000000e6`101f6090 000000e6`101f64b0 000000e6`101f5f90 : terra!ZN13SpatDataFrame9write_dbfENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbR11SpatOptions+0x54b54c 000000e6`101f5ef0 00007ffe`8fa0eaba : 00000219`9adc7890 000000e6`00000000 000000e6`101f5f70 00007ffe`91df7b40 : terra!ZN13SpatDataFrame9write_dbfENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbR11SpatOptions+0x55ca08 000000e6`101f5f20 00007ffe`8fa12846 : 00000219`9a6f1540 00000219`9ae41990 00000000`00000000 000000e6`101f64a0 : terra!ZN10SpatVector8read_ogrEP11GDALDatasetNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_St6vectorIdSaIdEES_b+0xfa 000000e6`101f6410 00007ffe`9196bdad : 00000219`8ab3bd70 00007ffe`af9cbc7a 00000219`9183a640 00000219`9d2ee488 : terra!ZN10SpatVector4readENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_S5_St6vectorIdSaIdEES_b+0x176 000000e6`101f6850 00007ffe`91993f2b : 000000e6`101f72f0 00007ffe`af9c5071 00000219`93b48460 00000219`9d28afa8 : terra!ZN4Rcpp10CppMethod6I10SpatVectorbNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_St6vectorIdSaIdEES1_bEclEPS1_PP7SEXPREC+0xdd 000000e6`101f6cc0 00007ffe`e9fa5631 : 00000000`00000009 00007ffe`af98d8ef 00000219`9dad4b30 00000003`af953c3f : terra!ZN4Rcpp6class_I10SpatVectorE14invoke_notvoidEP7SEXPRECS4_PS4_i+0xdb 000000e6`101f6d40 00007ffe`af960a30 : 00000000`00000000 000000e6`101f7028 000000e6`101f7030 000000e6`101f7050 : Rcpp!Z25CppMethod__invoke_notvoidP7SEXPREC+0x161 000000e6`101f6fd0 00007ffe`af9c5673 : 00000219`99a4c148 00000219`9d3074f0 00000219`99a4c030 00000219`00000005 : R!Rf_NewFrameConfirm+0x20d0 000000e6`101f74a0 00007ffe`af9c5eab : 00000219`9d1c5418 00000219`9d245900 00000219`9d2ec600 00000219`9cf82b50 : R!R_initAssignSymbols+0x1e0c3 000000e6`101f7740 00007ffe`af9c5468 : 00000219`99a4bfc0 00000219`8ab9c9e0 00000219`99a4bfc0 00007ffe`afc9cc64 : R!Rf_eval+0x72b 000000e6`101f77c0 00007ffe`af9ca6ec : 00000000`00000000 00000219`9cf82b50 00007ffe`b1b20e40 00000219`9cf82b18 : R!R_initAssignSymbols+0x1deb8 000000e6`101f7a60 00007ffe`af9cbafa : 00000219`9cf82b88 00000219`9d3074f0 00007ffe`b1b20e40 00000219`9d1c5418 : R!R_cmpfun1+0x389c 000000e6`101f7df0 00007ffe`af9c51b3 : 000000e6`101f7d00 00000219`8ab39e98 00000219`9d307918 00000219`90bf74e8 : R!Rf_applyClosure+0x1aa 000000e6`101f7e80 00007ffe`af9c5eab : 00000001`00000005 00000219`9d1c5418 00000219`9d1dbb58 00007ffe`b1b21080 : R!R_initAssignSymbols+0x1dc03 000000e6`101f8120 00007ffe`af9c5468 : 00000219`9cf86358 00000219`8ab9c9e0 00000219`9cf86358 00000000`00000000 : R!Rf_eval+0x72b 000000e6`101f81a0 00007ffe`af9c5468 : a2000000`00000000 00000000`00004005 00000219`9cf86be0 00000000`00004005 : R!R_initAssignSymbols+0x1deb8 000000e6`101f8440 00007ffe`af9c5eab : 00000219`8aac0000 000000e6`101f87a9 00000000`00000017 00007fff`420bb3c7 : R!R_initAssignSymbols+0x1deb8 000000e6`101f86e0 00007ffe`af9c5468 : 00000219`9cf870b0 00000219`8ab9c9e0 00000219`9cf870b0 00000219`975b8858 : R!Rf_eval+0x72b 000000e6`101f8760 00007ffe`af9ca6ec : 00007ffe`b1b20e20 00007ffe`b1b21080 00000000`00000000 00000219`913e4ce0 : R!R_initAssignSymbols+0x1deb8 000000e6`101f8a00 00007ffe`af9cbafa : 00000219`9cf87318 00000219`9d1c5418 00007ffe`b1b212c8 00000219`9d1c5878 : R!R_cmpfun1+0x389c 000000e6`101f8d90 00007ffe`af9b9964 : 00000000`000b0030 00000000`00000036 00000219`9d1c55d8 00000219`8eb90710 : R!Rf_applyClosure+0x1aa 000000e6`101f8e20 00007ffe`af9c5071 : 00000219`9cf74cd8 00000219`9d1c5878 00007ff7`8040f560 00000000`00000002 : R!R_initAssignSymbols+0x123b4 000000e6`101fa370 00007ffe`af9ca6ec : 00000000`00000000 000000e6`101fb740 00000219`95714a00 00007fff`420b5ba1 : R!R_initAssignSymbols+0x1dac1 000000e6`101fa610 00007ffe`af9cc87e : 00000219`9d1c5cd8 00000219`9d1c5878 00007ffe`b1b21190 00000219`90bf74e8 : R!R_cmpfun1+0x389c 000000e6`101fa9a0 00007fff`1fc13379 : 00000219`9cf75090 00000219`9cf64750 00000000`00000000 000000e6`101fae60 : R!R_execMethod+0x20e 000000e6`101faa30 00007ffe`afa0bb57 : 00000219`9cf64750 00000065`736f6c00 00000219`9cec0ed0 00000002`00000000 : methods!R_dispatchGeneric+0x4a9 000000e6`101fab00 00007ffe`af9bb45c : 00000002`00000002 00000001`0000000d 00000219`8ab3bbe8 0000001a`00000001 : R!R_set_standardGeneric_ptr+0x4e7 000000e6`101fab70 00007ffe`af9c5071 : 00000219`9cf5dfb0 00000219`9d1c5aa8 00000000`00000000 00007fff`3f7c6c4c : R!R_initAssignSymbols+0x13eac 000000e6`101fc0c0 00007ffe`af9ca6ec : 00000000`039505f4 00000000`00000078 00000219`91e3e930 00007fff`3f7c695e : R!R_initAssignSymbols+0x1dac1 000000e6`101fc360 00007ffe`af9cbafa : 00000219`9d1c5cd8 00000219`9d1c5aa8 00000219`9a6277f0 00000219`90bf74e8 : R!R_cmpfun1+0x389c 000000e6`101fc6f0 00007ffe`af9c51b3 : 00000219`91e3e930 00000000`000003a0 00000219`9d1c5b50 00000219`9daa6020 : R!Rf_applyClosure+0x1aa 000000e6`101fc780 00007ffe`af9f37bd : 2f3d4843`52415f52 00000000`00343678 000000e6`101fcbd0 00007fff`420c219c : R!R_initAssignSymbols+0x1dc03 000000e6`101fca20 00007ffe`af9f3b78 : 00000000`00000000 00000219`8aad4aa0 0000000f`00000000 00000219`8ac91500 : R!Rf_ReplIteration+0x23d 000000e6`101fca80 00007ffe`af9f3c12 : 00000000`00000002 00000219`8aac2070 00000000`00000001 00000000`00000000 : R!Rf_ReplIteration+0x5f8 000000e6`101fdb00 00007ff7`7fd313ce : 00000000`00000000 00000000`00000000 00000000`00000002 00000219`8ab30280 : R!run_Rmainloop+0x52 000000e6`101fdb30 00007ff7`7fd2a8ad : 00000219`8ab2a101 00000000`00000001 000000e6`101fdf40 000000e6`101fde60 : rsession_utf8+0xd113ce 000000e6`101fdd60 00007ff7`7f2da9e0 : 00000000`00000000 000000e6`101ffa20 00000000`00000000 00007ff7`8085a8d0 : rsession_utf8+0xd0a8ad 000000e6`101fe1e0 00007ff7`800f9750 : 00000000`00000000 00000000`00000000 00000219`8aad2020 00000000`00000000 : rsession_utf8+0x2ba9e0 000000e6`101ffba0 00007fff`41567034 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : rsession_utf8+0x10d9750 000000e6`101ffbe0 00007fff`420e2651 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x14 000000e6`101ffc10 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21 STACK_COMMAND: ~0s ; .cxr ; kb SYMBOL_NAME: ucrtbase!invoke_watson+18 MODULE_NAME: ucrtbase IMAGE_NAME: ucrtbase.dll FAILURE_BUCKET_ID: FAIL_FAST_INVALID_ARG_c0000409_ucrtbase.dll!invoke_watson OS_VERSION: 10.0.19041.1 BUILDLAB_STR: vb_release OSPLATFORM_TYPE: x64 OSNAME: Windows 10 IMAGE_VERSION: 10.0.19041.789 FAILURE_ID_HASH: {ff968da7-5196-0e9d-7c2c-c6a2c196fc27} Followup: MachineOwner --------- ```
dblodgett-usgs commented 2 years ago

By native build, do you mean the released Rtools42? Please simplify by avoiding any Rstudio packages in any source builds, use only the very simplest route. My installs for which no errors occur are just standard CRAN binary installs, though I have Rtools42, and even (not now) test versions of MXE-built libgdal.a testing updated drivers. I have a feeling that somewhere you have a component built with a non-standard build chain.

@rsbivand I mean that I installed sf by building the package with devtools::build() via Rstudio's build tools. I do have Rtools42 although I have to admit ignorance of all the nuances of the build infrastructure for compiled packages in Windows.

kadyb commented 2 years ago

I ran this code from @dblodgett-usgs and I also can confirm that on Windows 10 RStudio is crashing and R Terminal is hanging (for {terra} is the same). However, on Windows 8.1 it works OK. I have {sf} binary version from CRAN. Maybe different locale is the problem?

``` R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044) Matrix products: default locale: [1] LC_COLLATE=Polish_Poland.utf8 LC_CTYPE=Polish_Poland.utf8 LC_MONETARY=Polish_Poland.utf8 [4] LC_NUMERIC=C LC_TIME=Polish_Poland.utf8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] terra_1.6-17 sf_1.0-8 loaded via a namespace (and not attached): [1] Rcpp_1.0.9 magrittr_2.0.3 units_0.8-0 tidyselect_1.1.2 [5] R6_2.5.1 rlang_1.0.5 fansi_1.0.3 dplyr_1.0.10 [9] tools_4.2.1 grid_4.2.1 KernSmooth_2.23-20 utf8_1.2.2 [13] cli_3.4.0 e1071_1.7-11 DBI_1.1.3 class_7.3-20 [17] tibble_3.1.8 lifecycle_1.0.2 purrr_0.3.4 codetools_0.2-18 [21] vctrs_0.4.1 glue_1.6.2 proxy_0.4-27 compiler_4.2.1 [25] pillar_1.8.1 generics_0.1.3 classInt_0.4-7 pkgconfig_2.0.3 ``` ``` GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H PROJ "3.9.1" "3.4.3" "7.2.1" "true" "true" "7.2.1" ```
edzer commented 2 years ago

Great; I'm looking at @dblodgett-usgs stack trace for sf, and am completely puzzled why CPL_get_z_range seems to get called from within sf_from_ogrlayer. There's no reason for it, but there isn't even a call to CPL_get_z_range in that function. Should I understand STACK_TEXT as a stack trace or is it something else?

dblodgett-usgs commented 2 years ago

@edzer -- for the record, the sf STACK_TEXT came from a WinDbg DUMP after running the following while nc_test.gpkg does not exist -- it writes but bombs during read:


nc <- sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
nc <- dplyr::rename(nc, "cnty_unique_id" = CNTY_ID)
sf::write_sf(nc, "nc_test.gpkg")
sf::read_sf("nc_test.gpkg")

The full report is:

``` Microsoft (R) Windows Debugger Version 10.0.22621.1 AMD64 Copyright (c) Microsoft Corporation. All rights reserved. Loading Dump File [C:\Users\dblodgett\AppData\Local\CrashDumps\rsession-utf8.exe.23376.dmp] User Mini Dump File: Only registers, stack and portions of memory are available Symbol search path is: srv* Executable search path is: Windows 10 Version 19044 MP (16 procs) Free x64 Product: WinNt, suite: SingleUserTS Edition build lab: 19041.1.amd64fre.vb_release.191206-1406 Machine Name: Debug session time: Sun Sep 11 19:14:33.000 2022 (UTC - 5:00) System Uptime: not available Process Uptime: 0 days 0:00:57.000 ................................................................ .................................... This dump file has an exception of interest stored in it. The stored exception information can be accessed via .ecxr. (5b50.1c40): Security check failure or stack buffer overrun - code c0000409 (first/second chance not available) Subcode: 0x5 FAST_FAIL_INVALID_ARG For analysis of this file, run !analyze -v ucrtbase!invoke_watson+0x18: 00007fff`3f8e1208 cd29 int 29h 0:000> !analyze -v ******************************************************************************* * * * Exception Analysis * * * ******************************************************************************* *** WARNING: Unable to verify checksum for rsession-utf8.exe KEY_VALUES_STRING: 1 Key : Analysis.CPU.mSec Value: 3436 Key : Analysis.DebugAnalysisManager Value: Create Key : Analysis.Elapsed.mSec Value: 47151 Key : Analysis.Init.CPU.mSec Value: 1734 Key : Analysis.Init.Elapsed.mSec Value: 17072 Key : Analysis.Memory.CommitPeak.Mb Value: 290 Key : FailFast.Name Value: INVALID_ARG Key : FailFast.Type Value: 5 Key : Timeline.Process.Start.DeltaSec Value: 57 Key : WER.OS.Branch Value: vb_release Key : WER.OS.Timestamp Value: 2019-12-06T14:06:00Z Key : WER.OS.Version Value: 10.0.19041.1 Key : WER.Process.Version Value: 2022.7.1.0 FILE_IN_CAB: rsession-utf8.exe.23376.dmp NTGLOBALFLAG: 0 PROCESS_BAM_CURRENT_THROTTLED: 0 PROCESS_BAM_PREVIOUS_THROTTLED: 0 APPLICATION_VERIFIER_FLAGS: 0 CONTEXT: (.ecxr) rax=0000000000000001 rbx=0000000000000459 rcx=0000000000000005 rdx=0000000000000000 rsi=0000000080000000 rdi=000001900415ba60 rip=00007fff3f8e1208 rsp=0000005fb59f2d60 rbp=0000005fb59f2fd0 r8=0000000000000000 r9=0000000000000000 r10=0000000000000013 r11=0000000000000246 r12=0000005fb59f30c0 r13=0000019012f55040 r14=0000005fb59f2ef0 r15=3fffffffffffffff iopl=0 nv up ei pl nz na pe nc cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000202 ucrtbase!invoke_watson+0x18: 00007fff`3f8e1208 cd29 int 29h Resetting default scope EXCEPTION_RECORD: (.exr -1) ExceptionAddress: 00007fff3f8e1208 (ucrtbase!invoke_watson+0x0000000000000018) ExceptionCode: c0000409 (Security check failure or stack buffer overrun) ExceptionFlags: 00000001 NumberParameters: 1 Parameter[0]: 0000000000000005 Subcode: 0x5 FAST_FAIL_INVALID_ARG PROCESS_NAME: rsession-utf8.exe ERROR_CODE: (NTSTATUS) 0xc0000409 - The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application. EXCEPTION_CODE_STR: c0000409 EXCEPTION_PARAMETER1: 0000000000000005 FAULTING_THREAD: 00001c40 STACK_TEXT: 0000005f`b59f2d60 00007fff`3f8924b1 : 00000000`00000459 0000005f`b59f2fd0 00000000`80000000 00007fff`3f883a81 : ucrtbase!invoke_watson+0x18 0000005f`b59f2d90 00007fff`3f892379 : 00000000`7fffffff 00007fff`3f883496 00000000`00000459 00000000`80000000 : ucrtbase!_invalid_parameter+0x12d 0000005f`b59f2dd0 00007fff`3f897ff7 : 00000000`7fffffff 00000000`80000000 0000005f`b59f2fd0 00007fff`3f87fde6 : ucrtbase!invalid_parameter_noinfo+0x9 0000005f`b59f2e10 00007ffe`971e8bdb : 00000000`80000000 0000005f`b59f2fd0 0000005f`b59f2ef0 0000005f`b59f2fb0 : ucrtbase!strxfrm_l+0x57 0000005f`b59f2e90 00007ffe`971e8d8f : 00000190`0c088b11 0000005f`b59f3159 00000190`0c088b10 00000190`0c088b11 : sf!ZNKSt5ctypeIcE8do_widenEc+0x2079b 0000005f`b59f2f50 00007ffe`971e7d74 : 0000005f`b59f2fa0 00000190`0c088b10 00000190`0c088b11 0000005f`b59f2fc7 : sf!ZNKSt5ctypeIcE8do_widenEc+0x2094f 0000005f`b59f2f80 00007ffe`971e76f0 : 0000005f`b59f30c0 00000190`1219f478 00000190`0c088b10 00000190`0c088b11 : sf!ZNKSt5ctypeIcE8do_widenEc+0x1f934 0000005f`b59f2ff0 00007ffe`975d7d48 : 0000005f`b59f30c0 00000190`1219f478 0000005f`b59f3158 0000005f`b59f3159 : sf!ZNKSt5ctypeIcE8do_widenEc+0x1f2b0 0000005f`b59f3060 00007ffe`9721e88c : 0000005f`b59f3150 00007ffe`97399fff 00000000`0000001f 0000005f`b59f32cc : sf!ZTv0_n24_N4Rcpp8RostreamILb1EED1Ev+0x3b18 0000005f`b59f3130 00007ffe`9751a4c8 : 0000005f`b59f3250 0000005f`b59f3280 00000000`0000007f 00000000`00000000 : sf!ZNKSt5ctypeIcE8do_widenEc+0x5644c 0000005f`b59f3170 00007ffe`9751a965 : 0000005f`b59f3250 00000000`00000000 00000000`00000000 0000005f`00000020 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x6c038 0000005f`b59f31d0 00007ffe`97526343 : 0000005f`b59f3250 0000005f`b59f37c0 00000190`1219f400 00000190`128156d0 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x6c4d5 0000005f`b59f3230 00007ffe`97526964 : 0000005f`b59f36b0 00007ffe`00000008 0000005f`b59f3420 00007ffe`97396aae : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x77eb3 0000005f`b59f33e0 00007ffe`97526b79 : 0000005f`b59f36b0 00000190`0cc72d30 00000190`0cc72d30 00000190`0cc72d30 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x784d4 0000005f`b59f3470 00007ffe`975239d9 : 0000005f`b59f36b0 00007ffe`97396a58 0000005f`b59f37e0 00000000`00000000 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x786e9 0000005f`b59f34a0 00007ffe`975239f6 : 0000005f`b59f36b0 0000005f`b59f36b0 0000005f`b59f3550 00007ffe`97521875 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x75549 0000005f`b59f3510 00007ffe`97523ab9 : 0000005f`b59f36b0 00000000`00000000 0000005f`b59f35c0 00007ffe`971bfa35 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x75566 0000005f`b59f3580 00007ffe`97526d5c : 0000005f`b59f36b0 00000190`00000000 0000005f`00000000 00000000`00000011 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x75629 0000005f`b59f3600 00007ffe`97518e64 : 0000005f`b59f36b0 00007ffe`977a68f8 00007ffe`977a692d 00007ffe`9856fde8 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x788cc 0000005f`b59f3680 00007ffe`9745000b : 00007ffe`9856fdf0 00007ffe`977a68f8 00007ffe`977a692d 00007ffe`9856fde8 : sf!ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St9_IdentityIS5_ESt4lessIS5_ESaIS5_EE16_M_insert_uniqueIS5_EESt4pairISt17_Rb_tree_iteratorIS5_EbEOT_+0x6a9d4 0000005f`b59f3860 00007ffe`9744ff42 : 00007ffe`9856fde0 00007ffe`977a68f8 00007ffe`977a692d 0000005f`b59f38f8 : sf!ZNSt6vectorIySaIyEE17_M_realloc_insertIJyEEEvN9__gnu_cxx17__normal_iteratorIPyS1_EEDpOT_+0x5edb 0000005f`b59f38c0 00007ffe`9744fed1 : 00007ffe`9856fde0 00007ffe`977a68f8 00007ffe`977a692d 00000190`00000001 : sf!ZNSt6vectorIySaIyEE17_M_realloc_insertIJyEEEvN9__gnu_cxx17__normal_iteratorIPyS1_EEDpOT_+0x5e12 0000005f`b59f3920 00007ffe`95884d8a : 00007ffe`9856fde0 00007ffe`977a68f8 00000190`00000001 00000000`00000001 : sf!ZNSt6vectorIySaIyEE17_M_realloc_insertIJyEEEvN9__gnu_cxx17__normal_iteratorIPyS1_EEDpOT_+0x5da1 0000005f`b59f3950 00007ffe`95820dd5 : 0000005f`b59f4000 00000190`0cf8a5b8 00000190`0c088c30 00000000`00000001 : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x6d261a 0000005f`b59f3d90 00007ffe`958200ac : 00000190`0ccf35c0 00007ffe`97381558 0000005f`b59f44b8 00000000`00000000 : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x66e665 0000005f`b59f41a0 00007ffe`95826820 : 00000190`0ccf35c0 00007ffe`97381500 00000000`00000179 0000005f`b59f4240 : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x66d93c 0000005f`b59f41d0 00007ffe`9515bd03 : 00000190`0ccf35c0 01000190`00000001 00000190`09211e10 00007fff`00000142 : sf!Z15CPL_get_z_rangeN4Rcpp6VectorILi19ENS_15PreserveStorageEEEi+0x6740b0 0000005f`b59f4360 00007ffe`95161c13 : 0000005f`b59f4a70 00000190`0ccf35c0 00000000`00000000 00000190`0c088bb0 : sf!Z16sf_from_ogrlayerP8OGRLayerbbN4Rcpp6VectorILi14ENS1_15PreserveStorageEEENS2_ILi16ES3_EEb+0x63 0000005f`b59f4730 00007ffe`9514252d : 0000005f`b59f4a70 0000005f`b59f4970 00000190`0a509290 00000190`041cf078 : sf!Z12CPL_read_ogrN4Rcpp6VectorILi16ENS_15PreserveStorageEEES2_S2_S2_bNS0_ILi14ES1_EES2_S2_S2_bbbbi+0x923 0000005f`b59f48c0 00007ffe`af966d6c : 00000190`11c54df0 00000190`0bee66c8 00000190`0bee9e78 00000190`041cf190 : sf!sf_CPL_read_ogr+0x20d 0000005f`b59f4ae0 00007ffe`af96776d : 00000190`075dd198 0000005f`b59f4d88 0000005f`b59f4d90 0000005f`b59f4fc0 : R!Rf_NewFrameConfirm+0x840c 0000005f`b59f4d10 00007ffe`af9abdc4 : 00000190`07c31a48 00000190`07006e73 00000190`075dd2e8 00007ffe`b1b21080 : R!Rf_NewFrameConfirm+0x8e0d 0000005f`b59f5410 00007ffe`af9c5071 : 00000190`07c30628 00000190`075ddf98 00000190`11716110 00000000`00000000 : R!R_initAssignSymbols+0x4814 0000005f`b59f6960 00007ffe`af9ca6ec : 00000000`00000001 00000190`0a1aa088 00007ffe`b19b53bf 00000190`08b8c658 : R!R_initAssignSymbols+0x1dac1 0000005f`b59f6c00 00007ffe`af9cbafa : 00000190`07c54680 00000190`075ddf98 00000190`07c54220 00000190`075dedb8 : R!R_cmpfun1+0x389c 0000005f`b59f6f90 00007ffe`af9b9964 : 00000190`08d11e30 00000190`041d5dd0 00000190`075dd518 00007ffe`afca7e40 : R!Rf_applyClosure+0x1aa 0000005f`b59f7020 00007ffe`af9c5071 : 00000190`07c51658 00000190`075dedb8 00007ffe`b1b212d0 00000190`000004d0 : R!R_initAssignSymbols+0x123b4 0000005f`b59f8570 00007ffe`af9ca6ec : 00000190`041cf078 00000190`041cf190 00001fa0`0010000f 0053002b`002b0033 : R!R_initAssignSymbols+0x1dac1 0000005f`b59f8810 00007ffe`af9cbafa : 00000190`075de958 00000190`075dedb8 00007ffe`b1b21078 00000190`075de680 : R!R_cmpfun1+0x389c 0000005f`b59f8ba0 00007ffe`afa0937a : 00007ffe`b1b21078 00007ffe`af912d79 00000190`075de3a8 00007ffe`afa071d9 : R!Rf_applyClosure+0x1aa 0000005f`b59f8c30 00007ffe`afa098ec : 00000190`041cf190 00000190`07c50698 00000190`0420ca58 00007ffe`b1b212f8 : R!R_has_methods_attached+0x37a 0000005f`b59f8cb0 00007ffe`afa09be9 : 00000190`0a184838 00000190`113ab908 00000190`113ab8d0 00000190`09d53640 : R!R_has_methods_attached+0x8ec 0000005f`b59f8d60 00007ffe`af9ab7a1 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : R!R_has_methods_attached+0xbe9 0000005f`b59f9210 00007ffe`af9c5071 : 00000190`113ab898 00000190`075de680 00000000`00000001 00000000`0010000b : R!R_initAssignSymbols+0x41f1 0000005f`b59fa760 00007ffe`af9ca6ec : 00000000`00000000 00000190`09d53050 00000190`09d53040 00000190`0a95d2e0 : R!R_initAssignSymbols+0x1dac1 0000005f`b59faa00 00007ffe`af9cbafa : 00000190`07c64b60 00000190`075de680 00007ffe`b1b212c8 00000190`075ebf80 : R!R_cmpfun1+0x389c 0000005f`b59fad90 00007ffe`af9b9964 : 00000002`00000002 00000001`0000000d 00000190`075de3a8 0000001a`00000001 : R!Rf_applyClosure+0x1aa 0000005f`b59fae20 00007ffe`af9c5071 : 00000190`07c63640 00000190`075ebf80 00000000`00000000 00007fff`420bb86b : R!R_initAssignSymbols+0x123b4 0000005f`b59fc370 00007ffe`af9ca6ec : 00000000`00f803cd 00000000`00000091 00000190`0ade11e0 00000000`00000000 : R!R_initAssignSymbols+0x1dac1 0000005f`b59fc610 00007ffe`af9cbafa : 00000190`075ebca8 00000190`075ebf80 00000190`128137b0 00000190`0420fd38 : R!R_cmpfun1+0x389c 0000005f`b59fc9a0 00007ffe`af9c51b3 : 00000190`0ade11e0 00000000`000000c5 00000190`075ebe30 00000190`12519dc0 : R!Rf_applyClosure+0x1aa 0000005f`b59fca30 00007ffe`af9f37bd : 2f3d4843`52415f52 00000000`00343678 0000005f`b59fce80 00007fff`420c219c : R!R_initAssignSymbols+0x1dc03 0000005f`b59fccd0 00007ffe`af9f3b78 : 00000000`00000000 00000190`0414e720 0000000f`00000000 00000190`040d1f80 : R!Rf_ReplIteration+0x23d 0000005f`b59fcd30 00007ffe`af9f3c12 : 00000000`00000002 00000190`041e6ee0 00000000`00000001 00000000`00000000 : R!Rf_ReplIteration+0x5f8 0000005f`b59fddb0 00007ff7`7fd313ce : 00000000`00000000 00000000`00000000 00000000`00000002 00000190`041b1e40 : R!run_Rmainloop+0x52 0000005f`b59fdde0 00007ff7`7fd2a8ad : 00000190`041abd01 00000000`00000001 0000005f`b59fe1f0 0000005f`b59fe110 : rsession_utf8+0xd113ce 0000005f`b59fe010 00007ff7`7f2da9e0 : 00000000`00000000 0000005f`b59ffcd0 00000000`00000000 00007ff7`8085a8d0 : rsession_utf8+0xd0a8ad 0000005f`b59fe490 00007ff7`800f9750 : 00000000`00000000 00000000`00000000 00000190`04146bf0 00000000`00000000 : rsession_utf8+0x2ba9e0 0000005f`b59ffe50 00007fff`41567034 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : rsession_utf8+0x10d9750 0000005f`b59ffe90 00007fff`420e2651 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x14 0000005f`b59ffec0 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21 STACK_COMMAND: ~0s ; .cxr ; kb SYMBOL_NAME: ucrtbase!invoke_watson+18 MODULE_NAME: ucrtbase IMAGE_NAME: ucrtbase.dll FAILURE_BUCKET_ID: FAIL_FAST_INVALID_ARG_c0000409_ucrtbase.dll!invoke_watson OS_VERSION: 10.0.19041.1 BUILDLAB_STR: vb_release OSPLATFORM_TYPE: x64 OSNAME: Windows 10 IMAGE_VERSION: 10.0.19041.789 FAILURE_ID_HASH: {ff968da7-5196-0e9d-7c2c-c6a2c196fc27} Followup: MachineOwner --------- ```
rsbivand commented 2 years ago

Progress - after re-installing sf binary from CRAN cloud mirror, I'm also seeing the sf::read_sf("nc_test.gpkg") hang. Microsoft Windows [Version 10.0.19044.1889], this morning terra too.

Edit:

Not stable progress - after switching to st_() and omitting dplyr, I re-ran the new and original code in a for-loop, and no hangs were observed. So is this a transient case on first load of sf ??? Not always, Now I cannot re-create the hang even in a new R session (R.exe in Windows terminal console).

rsbivand commented 2 years ago

On the Windows PC on which sf::read_sf("nc_test.gpkg") just failed:

> nc <- sf::st_read(system.file("gpkg/nc.gpkg", package = "sf"))
Reading layer `nc.gpkg' from data source
  `C:\Users\RB\AppData\Local\R\win-library\4.2\sf\gpkg\nc.gpkg'
  using driver `GPKG'
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS:  NAD27
> names(nc)
 [1] "AREA"      "PERIMETER" "CNTY_"     "CNTY_ID"   "NAME"      "FIPS"
 [7] "FIPSNO"    "CRESS_ID"  "BIR74"     "SID74"     "NWBIR74"   "BIR79"
[13] "SID79"     "NWBIR79"   "geom"
> names(nc)[4] <- "cnty_unique_id"
> names(nc)
 [1] "AREA"           "PERIMETER"      "CNTY_"          "cnty_unique_id"
 [5] "NAME"           "FIPS"           "FIPSNO"         "CRESS_ID"
 [9] "BIR74"          "SID74"          "NWBIR74"        "BIR79"
[13] "SID79"          "NWBIR79"        "geom"
> sf::st_write(nc, "nc_test0.gpkg")
Writing layer `nc_test0' to data source `nc_test0.gpkg' using driver `GPKG'
Writing 100 features with 14 fields and geometry type Multi Polygon.
> sf::st_read("nc_test0.gpkg")
Reading layer `nc_test0' from data source `C:\Users\RB\work\nc_test0.gpkg' using driver `GPKG'
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS:  NAD27
>

that is:

nc <- sf::st_read(system.file("gpkg/nc.gpkg", package = "sf"))
names(nc)[4] <- "cnty_unique_id"
sf::st_write(nc, "nc_test0.gpkg")
sf::st_read("nc_test0.gpkg")

passes, as does terra::vect("nc_test0.gpkg").

edzer commented 2 years ago

@rhijmans maybe you could take a look what is going on here, being familiar with windows debugging?

dblodgett-usgs commented 2 years ago

@rsbivand For the record, your st_read version also bombs my rstudio.

rhijmans commented 2 years ago

I see the same problem (R hanging). This happens when trying to read geometries or attributes or even the srs from the "poLayer" (obtained with, e.g. "poLayer = poDS->GetLayer(0)"). That makes it difficult to further debug this for me.

For example, the below fails with the offending file

bool SpatVector::test(std::string filename) { 
    GDALDataset *poDS = static_cast<GDALDataset*>(GDALOpenEx(filename.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL ));
    OGRSpatialReference *poSRS = poDS->GetLayer(0)->GetSpatialRef();
    return true;
}

You can call it like this with terra-devel

library(sf)
library(terra)
fin <- system.file("gpkg/nc.gpkg", package = "sf")
fout <- "nc_test0.gpkg"
if (!file.exists(fout)) {
    nc <- sf::st_read(fin)
    names(nc)[4] <- "cnty_unique_id"
    sf::st_write(nc, fout)
}
v <- terra::vect()@ptr

v$test(fin)
[1] TRUE

# this hangs
v$test(fout)
edzer commented 2 years ago

@rouault did you come across a problem with GeoPackage file reading when one of the field contains the string unique?

rouault commented 2 years ago

did you come across a problem with GeoPackage file reading when one of the field contains the string unique?

I suspect you might hit https://github.com/OSGeo/gdal/blob/master/ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp#L351 . Do you use a outdated compiler (GCC < 5) to build GDAL ? There are known issues in the early implementations of C++ regexp capabilities

rhijmans commented 2 years ago

As far as I can see, Rtools42 (the toolchain used to build R and R packages for windows) uses

gcc --version
#gcc (GCC) 10.3.0
rouault commented 2 years ago

can you try just with ogrinfo / ogr2ogr ? Maybe it is an issue with the mingw implementation of C++ regexp, but that would be strange as GDAL has a msys2 CI setup where testing of tables with unique in column name is done (https://github.com/OSGeo/gdal/blob/4de8becdd4ff4d656c3d7f8ab2cf3baa2a5005b9/autotest/ogr/ogr_gpkg.py#L2275) and it passes fine on it

edzer commented 2 years ago

@rhijmans or someone else with an R / windows machine: you could try ogr2ogr in the same R setup e.g. with sf::gdal_utils("vectortranslate", "nc_test0.gpkg", "nc_test0.json") ; ogrinfo is not available through gdal_utils.

kadyb commented 2 years ago

@rhijmans or someone else with an R / windows machine: you could try ogr2ogr in the same R setup e.g. with sf::gdal_utils("vectortranslate", "nc_test0.gpkg", "nc_test0.json") ; ogrinfo is not available through gdal_utils.

It crashed for me in RStudio.

rhijmans commented 2 years ago

I can confirm that the regex works (code here)

v$test(fin)
#regex works
#[1] TRUE

ogr2ogr via sf also hangs for me

rsbivand commented 2 years ago

The code at: https://github.com/OSGeo/gdal/blob/8e4c84b5103a832f5f0ca507ce2eec36f479f994/ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp#L338-L445 applies to SQLite UNIQUE contraints, but the test appears to try to handle columns/fields with toupper("unique") in the column name as unique. If in addition std::regex is buggy but is marked as OK - the test for a working std::regex is very simple - odd behaviour may follow. The specific commit seems to be: https://github.com/OSGeo/gdal/commit/455bf3c255ee78dc70116ca2e2b1a37aaecd0799#diff-4427c5e19b00d7ce062221d9d671df58c1f622d1689375ced2a6cc61dbe8c3c4. Unique constraints were added to some vector drivers from 3.2.0.

kalibera commented 2 years ago

I can reproduce the problem in the trunk build of Rtools42 ("ucrt3"), stacktrace pointing to regex compilation in SQLGetUniqueFieldUCConstraints. I will try rebuilding Rtools42 with gdal modified to assert that the regexes are buggy (always) in this function. It would still be good to know if this is a bug in the std::regex implementation (and report if so), or in gdal.

rsbivand commented 2 years ago

The only uses of regex in GDAL master:

$ grep regex */*/*/*.cpp
ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp:#include <regex>
ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp:        const auto regex = std::regex(R"((\w+)+\((\d+(,\d+)*)\)$)");
ogr/ogrsf_frmts/hana/ogrhanatablelayer.cpp:        std::regex_search(typeDef, match, regex);
ogr/ogrsf_frmts/sqlite/ogrsqliteregexp.cpp:#include "ogrsqliteregexp.h"
ogr/ogrsf_frmts/sqlite/ogrsqliteregexp.cpp:        sqlite3_result_error(ctx, "no regexp", -1);
ogr/ogrsf_frmts/sqlite/ogrsqliteregexp.cpp:        sqlite3_result_error(ctx, "no regexp", -1);
ogr/ogrsf_frmts/sqlite/ogrsqlitesqlfunctions.cpp:#include "ogrsqliteregexp.cpp" /* yes the .cpp file, to make it work on Windows with load_extension('gdalXX.dll') */
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:#include <regex>
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:    // std::regex in gcc < 4.9 is broken
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:        static int hasWorkingRegex = std::regex_match("c", std::regex("a|b|c"));
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:                static const std::regex sFieldIdentifierRe {
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:                    std::regex_constants::icase};
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:                if( std::regex_search(fieldStr, uniqueFieldMatch, sFieldIdentifierRe) )
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:                    static const std::regex sFieldIndexIdentifierRe {
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:                    if( std::regex_search(indexDefinition, uniqueFieldMatch,
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:    catch( const std::regex_error& e )
ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp:        CPLError(CE_Failure, CPLE_AppDefined, "regex_error: %s", e.what());
$ grep regex */*/*.cpp
frmts/rasdaman/rasdamandataset.cpp:#include "regex.h"
frmts/rasdaman/rasdamandataset.cpp:  // regex for parsing options
frmts/rasdaman/rasdamandataset.cpp:  regex_t optionRegEx;
frmts/rasdaman/rasdamandataset.cpp:  // regex for parsing query
frmts/rasdaman/rasdamandataset.cpp:  regex_t queryRegEx;
frmts/rasdaman/rasdamandataset.cpp:    CPLError(CE_Failure, CPLE_AppDefined, "Internal error at compiling option parsing regex: %s", errbuffer);
frmts/rasdaman/rasdamandataset.cpp:    CPLError(CE_Failure, CPLE_AppDefined, "Internal error at compiling option parsing regex: %s", errbuffer);
frmts/rasdaman/rasdamandataset.cpp:  // executing option parsing regex on the connection string and checking if it succeeds
frmts/rasdaman/rasdamandataset.cpp:  result = regexec(&optionRegEx, connString, 10, matches, 0);
frmts/rasdaman/rasdamandataset.cpp:  result = regexec(&queryRegEx, queryParam, 10, matches, 0);
frmts/vrt/vrtderivedrasterband.cpp:                                              "fromregex", // numpy.fromregex
kalibera commented 2 years ago

With patched gdal (to assert std::regex is buggy in SQLGetUniqueFieldUCConstraints), Roger's testcase finishes for me (an a system where it got stuck before):

> nc <- sf::st_read(system.file("gpkg/nc.gpkg", package = "sf"))
Reading layer `nc.gpkg' from data source
  `C:\msys64\home\tomas\trunk\library\sf\gpkg\nc.gpkg' using driver `GPKG'
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS:  NAD27
> names(nc)[4] <- "cnty_unique_id"
> sf::st_write(nc, "nc_test0.gpkg")
Writing layer `nc_test0' to data source `nc_test0.gpkg' using driver `GPKG'
Writing 100 features with 14 fields and geometry type Multi Polygon.
> sf::st_read("nc_test0.gpkg")
Reading layer `nc_test0' from data source
  `C:\msys64\home\tomas\trunk\src\gnuwin32\nc_test0.gpkg' using driver `GPKG'
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS:  NAD27

This new build of Rtools42 is now at https://www.r-project.org/nosvn/winutf8/ucrt3 (file gcc10_ucrt3_full_5336.tar.zst, svn revision 5336). I took this opportunity to re-generate the patch for gdal-3.5, but the only real change is:

diff -Nru gdal-3.5.0-orig/ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp gdal-3.5.0-patched/ogr/ogrsf_fr
mts/sqlite/ogrsqliteutility.cpp
--- gdal-3.5.0-orig/ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp 2022-05-10 10:03:38.000000000 -0400
+++ gdal-3.5.0-patched/ogr/ogrsf_frmts/sqlite/ogrsqliteutility.cpp      2022-09-13 14:35:48.582070744
 -0400
@@ -349,7 +349,8 @@
     std::set<std::string> uniqueFieldsUC;

     // std::regex in gcc < 4.9 is broken
-#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 5
+    // seems still broken in newer versions, including gcc 10.3
+#if 0

     try
     {
rsbivand commented 2 years ago

Thanks @kalibera , very useful! Could you perhaps please provide links to updated sf and terra binaries for @dblodgett-usgs and @kadyb and others? This would enlarge the pool of testers.

Is perhaps the MXE/Msys2 regex interacting with UCRT? The GDAL Msys2 CI is likely to be using legacy CRT, although I cannot see where that choice would be made in https://github.com/OSGeo/gdal/tree/master/.github/workflows/mingw_w64. So this R/MXE/UCRT detection of a string handling problem might also be attacked by re-checking the std::regex component, provided I think by libsystre. I see that a ucrt variant is available, but maybe not tested; the underlying version 1.0.1 seems to be 8 years old, so pre-UCRT.

The Rasdaman GDAL raster driver isn't built in MXE libgdal, it needs raslib which nobody has asked for. The HANA vector driver needs odbc-cpp-wrapper, but again nobody has asked for it. So only the SQLite and GPGK vector drivers touch code in GDAL using regex.

kalibera commented 2 years ago

The binaries for sf and terra are not built, yet, because the system works in cycles and hasn't yet gotten to building them with the new Rtools42. I've just tested locally using the new build of Rtools42. https://www.r-project.org/nosvn/winutf8/ucrt3 has a stamp file, which is currently r_packages_5330_built_by_R-devel-win-82844-5286-5245.exe.stamp. Once the second number after R-devel-win (now 5286), becomes 5336, the new binaries are ready under https://www.r-project.org/nosvn/winutf8/ucrt3/CRAN/bin/windows/contrib/4.3/

Looking at the CI workflow (but not knowing anything about it), it runs on Debian or Ubuntu Linux in wine and builds gdal using mingw cross-compilers available for Linux in the distribution. These target MSVCRT. For checking gdal for use with R, it would be possible to use the cross-compilers distributed with Rtools42, instead, which target UCRT. Ideally with all the pre-built static libraries which are included in Rtools42. The workflow script would not have to change much.

rsbivand commented 2 years ago

Thanks again @kalibera . Once 5336 has propagated, will it be possible to extend coverage to R-patched - so contrib/4.2 ? If that could be done, and if so, when in place, what would be the best way to trigger fresh binary builds of packages using GDAL?

rouault commented 2 years ago

The CI I was referring to is https://github.com/OSGeo/gdal/blob/8e4c84b5103a832f5f0ca507ce2eec36f479f994/.github/workflows/cmake_builds.yml#L298 which uses mingw64 / msys2 on a Windows builder (the mingw_w64 one is a bit kludgy) Anyway it really looks like this is a toolchain issue. Disabling std::regex usage in GDAL in SQLGetUniqueFieldUCConstraints() is a workaround, and should ideally be fixed more cleanly. We might want to use std::regex in GDAL in the future in parts that can't be disabled.

rsbivand commented 2 years ago

@rouault yes, the underlying problem seems to be a MSVCRT libsystre in Msys2, which only fails in some settings (my guess). Windows binaries for R are an early adopter of UCRT among FOSS: https://blog.r-project.org/, particularly https://blog.r-project.org/2021/12/07/upcoming-changes-in-r-4.2-on-windows/index.html https://blog.r-project.org/2022/06/16/upcoming-changes-in-r-4.2.1-on-windows/index.html. It appears that OSGeo4W are MSVCRT, possibly because they move at the speed of the slowest included library or application. The patch @kalibera adds is only in the MXE UCRT build train for immediate protection beause a working GPKG driver is vital now. Fixing (or checking) the upstream Msys2 libsystre for behaviour under UCRT would be preferable, but it is upstream of this case. I guess @kalibera, who is in touch with MXE developers, could raise an issue there, but creating a clear test is not easy.

kalibera commented 2 years ago

Thanks again @kalibera . Once 5336 has propagated, will it be possible to extend coverage to R-patched - so contrib/4.2 ? If that could be done, and if so, when in place, what would be the best way to trigger fresh binary builds of packages using GDAL?

No, I am not building packages for R 4.2 with unreleased versions of Rtools42, only with R-devel, that would require too much of computational resources. You can test with R-devel (using my binaries or building the packages from source) and using R 4.2 (building the packages from source).

rsbivand commented 2 years ago

For build 5286-5107 of Rtools42 (and subsequent), could those testing please note that sf src/Makefile.ucrt needs updating to add in -lkea -lhdf5_hl -hdf5_cpp where -lhdf5_hl is now. In response to a user request, the KEA driver was added in this build of Rtools42. The same applies to terra, etc. rtools42-5253-5107-signed.exe is released Rtools42 matching the src/Makefile.ucrt files currently present in the source packages. @kalibera is there a way of conditioning on the Rtools build number in src/Makefile.ucrt - if so, do you have an example of a package using version conditioning?

kalibera commented 2 years ago

We might want to use std::regex in GDAL in the future in parts that can't be disabled.

There are known issues with std::regex in multi-byte locales (R runs in UTF-8). See below. The tesseract thread includes a repro that was as far as I understand done using a different UCRT toolchain (not Rtools42). The GCC bug report says that std::regex may get deprecated.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98723 https://github.com/tesseract-ocr/tesseract/issues/3830 https://github.com/sg16-unicode/sg16/issues/57