Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sf::st_layers hanging R / bombing rstudio #1995

Closed
dblodgett-usgs opened this issue Sep 9, 2022 · 73 comments
Closed

sf::st_layers hanging R / bombing rstudio #1995

dblodgett-usgs opened this issue Sep 9, 2022 · 73 comments

Comments

@dblodgett-usgs
Copy link
Contributor

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
Copy link
Member

edzer commented Sep 9, 2022

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
Copy link
Member

rsbivand commented Sep 9, 2022

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
Copy link
Contributor Author

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
Copy link
Member

rsbivand commented Sep 9, 2022

Does released sf have the same problem?

@dblodgett-usgs
Copy link
Contributor Author

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
Copy link
Member

rsbivand commented Sep 9, 2022

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

@dblodgett-usgs
Copy link
Contributor Author

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

@dblodgett-usgs dblodgett-usgs changed the title Output emitted by sf::st_layers is bombing rstudio. sf::st_layers hanging R / bombing rstudio Sep 9, 2022
@dblodgett-usgs
Copy link
Contributor Author

dblodgett-usgs commented Sep 9, 2022

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

edzer commented Sep 10, 2022

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
Copy link
Member

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
Copy link
Contributor Author

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

@rsbivand
Copy link
Member

Do you know which mirror was used?

@dblodgett-usgs
Copy link
Contributor Author

dblodgett-usgs commented Sep 10, 2022

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
Copy link
Member

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
Copy link
Member

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

@dblodgett-usgs
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor

kadyb commented Sep 11, 2022

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
Copy link
Member

edzer commented Sep 11, 2022

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
Copy link
Contributor Author

@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
Copy link
Member

rsbivand commented Sep 12, 2022

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
Copy link
Member

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
Copy link
Member

edzer commented Sep 12, 2022

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

@rsbivand
Copy link
Member

@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
Copy link
Contributor

kalibera commented Sep 14, 2022

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
Copy link
Member

rsbivand commented Sep 14, 2022

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
Copy link
Contributor

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
tesseract-ocr/tesseract#3830
sg16-unicode/sg16#57

@kalibera
Copy link
Contributor

kalibera commented Sep 14, 2022

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?

Yes, the UCRT3 builds (using R-devel and unreleased version of Rtools42) automatically apply patches, which also adjust the linking, but if one tests using R 4.2. and unreleased Rtools42, one has to apply the patch manually. The patches used in the last build are available here: https://www.r-project.org/nosvn/winutf8/ucrt3/patches/CRAN/

The patches change the linking unconditionally. There is no prescribed way of conditioning as far as I know and it is a rare problem (4 packages currently have patches changing linking). Perhaps you could check for presence of files (headers, libraries), a bit like configure does, so e.g. check for kea. A new major release of R might require bigger changes, but then one could in principle conditionalize on R version. An installation of Rtools42 (from installer and toolchain bundle) has meta-data in files (.version, also list of MXE packages), but I would myself choose rather checks for presence of files as they are more general and portable. If anyone still had preference for the meta-data files, I think the right way would be to first discuss with the CRAN repository maintainers.

@rsbivand
Copy link
Member

Ok, @kalibera , hot patching makes good sense, thanks.

@rsbivand
Copy link
Member

rsbivand commented Sep 14, 2022

Here are binary builds of terra and sf with the 5336 libgdal - one 7z archive for each of R-devel and R-4.2.1: https://drive.google.com/drive/folders/1aG5XsjkPAO35aUWLSImlB8_eWg47Gxno?usp=sharing. Please do not trust these too much, they pass R CMD check, but will not be identical with those from the actual build system. The package source code was manually patched for the reinstated KEA driver.

Gdrive folder updated with copies of the source tarballs and fresh builds of the binaries from these tarballs, about Sept. 15, 10:30 CEST.

@kalibera
Copy link
Contributor

Thanks, I am now working on a bigger update of Rtools42, which will include more than this work-around, so the packages built on my system will get overwritten with even newer ones. So your builds may be good for reference if anyone needed to test only this change and nothing more.

@rouault
Copy link
Contributor

rouault commented Sep 14, 2022

OSGeo/gdal#6359 removes the use of std::regex in the OGR SQLite&GPKG drivers

@rsbivand
Copy link
Member

@rouault: thanks! As I read the commit, was the previous code looking in the field string rather than the table definition for the unique constraint declaration? A pity we didn't hit this issue before 3.5.2 was released.

@dblodgett-usgs
Copy link
Contributor Author

@rsbivand -- sorry to be dense, how should I be installing these binary builds? I'm getting errors with devtools::install(... quick=TRUE)

@rouault
Copy link
Contributor

rouault commented Sep 14, 2022

in the field string rather than the table definition for the unique constraint declaration?

The previous version looked at fieldStr, which contained each column definition, extracted from tableDefinition, split on comma. Anyway the new version should hopefully be at least as good, and probably better, than the previous one, as I assume the previous one might have had issues if comma were found in column name or DEFAULT 'some default value, with comma' clauses.

@rsbivand
Copy link
Member

@dblodgett-usgs install.packages("sf_1.0-9.zip")

@dblodgett-usgs
Copy link
Contributor Author

🎉 You guys are 🧙 level.

 library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.5.0, PROJ 7.2.1; sf_use_s2() is TRUE
 nc <- read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
 names(nc)[4] <- "cnty_unique_id"
 write_sf(nc, "nc_test.gpkg")
 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

 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-9
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9.1       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         R6_2.5.1          
#> [33] fansi_1.0.3        rmarkdown_2.16     purrr_0.3.4        magrittr_2.0.3    
#> [37] htmltools_0.5.3    units_0.8-0        KernSmooth_2.23-20 utf8_1.2.2        
#> [41] stringi_1.7.8      proxy_0.4-27
 
sf_extSoftVersion()
#>           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
#>        "3.9.1"        "3.5.0"        "7.2.1"         "true"         "true" 
#>           PROJ 
#>        "7.2.1"

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

@rsbivand
Copy link
Member

rsbivand commented Sep 14, 2022

Thanks! I'll update the 7z's tomorrow with sources (done 15/9 10:30 CEST). Actually the issue has helped improve GDAL too, so a "unique" contribution.

@kalibera
Copy link
Contributor

To catch things like this, sooner, on Windows, one would have to run tests in UTF-8, for which one would have to use UCRT and a UCRT toolchain, and one would have to set UTF-8 to be the native encoding via the fusion manifest (at build time via the manifest file, as R does it). It could be done using R/R packages and Rtools42 (MXE with some updates). There are number of patches that are now being done downstream to make gdal work (https://svn.r-project.org/R-dev-web/trunk/WindowsBuilds/winutf8/ucrt3/toolchain_libs/mxe/src/gdal-1-fixes.patch) and as always, it would be nice if the upstream code already could be built and used with UCRT without such downstream patching.

So, it would be nice if the upstream MXE could have up to date versions of gdal etc (not having to patch downstream in Rtools42) and if upstream gdal etc could work with UCRT/UTF-8 (not having to patch downstream in Rtools42). That would increase the chances problems are found in time and solved properly.

@rsbivand
Copy link
Member

@kalibera This recalls https://blog.r-project.org/2019/03/28/use-of-c-in-packages/index.html, but here the problem has been rushing forward without awareness that saying std:: doesn't mean problem solved for ever across changing platforms. Now we probably need to screen both packages and external software for use of std::regex not only for UCRT but because it may be withdrawn in the future for all platforms; @eddelbuettel, might Rcpp screen relevant packages? For external software, we have Windows and macOS binary builds with our own builds of libraries, but otherwise we'll have to rely on the upstream packagers or library maintainers. Here the rapid response by @rouault is a great example.

@kalibera
Copy link
Contributor

My blog was primarily against using C++ to interface with R, not against C++ in principle. If a library independent on R internally uses C++, without ever calling back to R (or allocating from R heap, throwing exceptions/jumping around R stack frames), that's ok. Yes, checking C++ in R packages for potential use of std::regex would be useful.

@eddelbuettel
Copy link
Contributor

eddelbuettel commented Sep 15, 2022

Yes, checking C++ in R packages for potential use of std::regex would be useful.

So let R CMD check do it. Rcpp has nothing to do with any of this, neither mandates nor promotes any C++ components. And of course only uses .Call(), a C interface, to communicate with R.

@rsbivand
Copy link
Member

So CRAN and Bioc teams would be the ones to check.

@rhijmans
Copy link
Contributor

rhijmans commented Sep 18, 2022

Here is another GDAL issue that appears to be related to the R toolchain on Windows. In short, this HDF5 file can be read on linux but not windows. This problem happens with "terra" and also with "stars".

LINUX

x <- rast("hd2011010000.scu")
#Warning message:
#[rast] unknown extent
y <- x * 1

y
#class       : SpatRaster
#dimensions  : 536, 536, 1  (nrow, ncol, nlyr)
#resolution  : 1, 1  (x, y)
#extent      : 0, 536, 0, 536  (xmin, xmax, ymin, ymax)
#coord. ref. :
#source      : memory
#name        : hd2011010000
#min value   :         -999
#max value   :           15

WINDOWS

x <- rast("hd2011010000.scu")
#Warning message:
#[rast] unknown extent
y <- x * 1
#Warning messages:
#1: H5Dread() failed for block. (GDAL error 1) 
#2: HDF5:"hd2011010000.scu"://dataset_DXk/image, band 1: IReadBlock failed at X offset 0, Y offset 0: 
#                 H5Dread() failed for block. (GDAL error 1) 

y
#class       : SpatRaster 
#dimensions  : 536, 536, 1  (nrow, ncol, nlyr)
#resolution  : 1, 1  (x, y)
#extent      : 0, 536, 0, 536  (xmin, xmax, ymin, ymax)
#coord. ref. :  

The second set of warnings should really be an Error because y has no values. and that is what "stars" give you:

s <- stars::read_stars("hd2011010000.scu")
#Error in CPL_read_gdal(as.character(x), as.character(options), as.character(driver),  : 
#  read failure
#In addition: Warning messages:
#1: In CPL_read_gdal(as.character(x), as.character(options), as.character(driver),  :
#  GDAL Error 1: H5Dread() failed for block.
#2: In CPL_read_gdal(as.character(x), as.character(options), as.character(driver),  :
#  GDAL Error 1: HDF5:"hd2011010000.scu"://dataset_DXk/image, band 1: IReadBlock failed at X #offset 0, Y offset 0: H5Dread() failed for block.

@rsbivand
Copy link
Member

@rhijmans which versions of the library used by the driver are being used? The windows version will be that of MXE in the ucrt3 builds, presumably released Rtools42, not my test build with the unreleased version of libgdal, which version in your linux, and how was thst gdal built and installed?

@kalibera
Copy link
Contributor

Here is another GDAL issue that appears to be related to the R toolchain on Windows.

Please note that std::regex is unreliable also on other platforms (seen on macOS at least with R packages as I've learned now). It is not specific to Windows (nor to Rtools42).

@rhijmans
Copy link
Contributor

@rsbivand: This fails on windows with the old (in R 3.6, GDAL 3.2.1) and new (UCRT) RTools using GDAL 3.4.3. It works for me on Ubuntu or Debian with GDAL 2.2.3, 2.4.0, and 3.4.0, and you showed that it works in Fedora with GDAL 3.5.2. (and you refer to the HDF lib versions as well, which may be helpful).

@kalibera: point well taken that the std::regex problems are not a Rtools issue. But this seems to be caused by how the HDF5 lib is built for R on windows.

@rouault solved a (perhaps) similar issue with HDF and OSGeo4W

@rsbivand
Copy link
Member

@rhijmans From reading the OSGeo4W issue, it may be that there is something odd happening when HDF5 is static rather than dynamic too. It would be interesting to see whether the error seen in R on Windows binary packages can be reproduced without R and the packages using MXE-built GDAL apps. These are not distributed, so someone will have to run a custom cross-compilation. Can you establish whether there is a useful HDF5 test suite on Windows before the HDF5 libraries are used when GDAL is built? Are there issues raised about Windows builds for HDF5 itself?

@kalibera
Copy link
Contributor

This thread may be hard to follow when this is no longer about the std::regex.

Still, I think the problem with HDF5 is that the szip is not supported (it is not part of MXE), but the file uses it. The output with the current (unreleased yet) UCRT3 Rtools42 build is:

> library(terra)
terra 1.6.17
> x <- rast("hd2011010000.scu")
Warning message:
[rast] unknown extent

> y <- x * 1
HDF5-DIAG: Error detected in HDF5 (1.12.0) thread 0:
  #000: ../../src/H5Dio.c line 192 in H5Dread(): can't read data
    major: Dataset
    minor: Read failed
  #001: ../../src/H5VLcallback.c line 2080 in H5VL_dataset_read(): dataset read failed
    major: Virtual Object Layer
    minor: Read failed
  #002: ../../src/H5VLcallback.c line 2046 in H5VL__dataset_read(): dataset read failed
    major: Virtual Object Layer
    minor: Read failed
  #003: ../../src/H5VLnative_dataset.c line 167 in H5VL__native_dataset_read(): can't read data
    major: Dataset
    minor: Read failed
  #004: ../../src/H5Dio.c line 567 in H5D__read(): can't read data
    major: Dataset
    minor: Read failed
  #005: ../../src/H5Dchunk.c line 2594 in H5D__chunk_read(): unable to read raw data chunk
    major: Low-level I/O
    minor: Read failed
  #006: ../../src/H5Dchunk.c line 3957 in H5D__chunk_lock(): data pipeline read failed
    major: Dataset
    minor: Filter operation failed
  #007: ../../src/H5Z.c line 1311 in H5Z_pipeline(): required filter 'szip' is not registered
    major: Data filters
    minor: Read failed
  #008: ../../src/H5PLint.c line 274 in H5PL_load(): search in path table failed
    major: Plugin for dynamically loaded library
    minor: Can't get value
  #009: ../../src/H5PLpath.c line 604 in H5PL__find_plugin_in_path_table(): search in path C:\Progra
mData\hdf5\lib\plugin encountered an error
    major: Plugin for dynamically loaded library
    minor: Can't get value
  #010: ../../src/H5PLpath.c line 734 in H5PL__find_plugin_in_path(): can't open directory
    major: Plugin for dynamically loaded library
    minor: Can't open directory or file
Warning messages:
1: H5Dread() failed for block. (GDAL error 1)
2: HDF5:"C:/msys64/home/tomas/hd2011010000.scu"://dataset_DXk/image, band 1: IReadBlock failed at X
offset 0, Y offset 0: H5Dread() failed for block. (GDAL error 1)

and szip is indeed disabled in the HDF5 build.

@rsbivand
Copy link
Member

@kalibera Thanks! I followed up on rspatial/terra#686 as the initial terra issue.

@edzer edzer closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants