Skip to content

Serialization of s2 geography data results in a segfault #259

Open
@tzakharko

Description

@tzakharko

I am unable to work with serialized s2 data since it crashes R for me (tested on Apple Silicon, R version 4.4.1). Note: s2_points work correctly.

Reprex:

p <- s2::s2_geog_point(0, 0)
data <- serialize(p, NULL)
unserialize(data)

Output:

 *** caught segfault ***
address 0x0, cause 'invalid permissions'

Traceback:
 1: wk_handle.s2_geography(handleable, wkt_format_handler(precision = precision,     trim = trim, max_coords = max_coords), ...)
 2: wk_handle(handleable, wkt_format_handler(precision = precision,     trim = trim, max_coords = max_coords), ...)
 3: wk::wk_format(x, precision = precision, max_coords = max_coords,     trim = trim)
 4: format.s2_geography(utils::head(x, max_print))
 5: format(utils::head(x, max_print))
 6: print.wk_vctr(x)
 7: (function (x, ...) UseMethod("print"))(x)
An irrecoverable exception occurred. R is aborting now ...

More information

It appears that the external pointer data is not being restored correctly — note how the inner extptr is set to 0x0 for the unserialized data.

p <- s2::s2_geog_point(0, 0)

.Internal(inspect(p))
#> @12b1c80a0 19 VECSXP g0c1 [OBJ,REF(3),ATT] (len=1, tl=0)
#>   @12b1dac08 22 EXTPTRSXP g0c0 [REF(2)] <0x129f040a0>
#> ATTRIB:
#>   @12b1df0a8 02 LISTSXP g0c0 [REF(1)] 
#>     TAG: @15a0111d0 01 SYMSXP g1c0 [MARK,REF(33769),LCK,gp=0x6000] "class" (has value)
#>     @14a2c06c8 16 STRSXP g0c2 [REF(1)] (len=2, tl=0)
#>       @13bb1a348 09 CHARSXP g1c2 [MARK,REF(130),gp=0x61,ATT] [ASCII] [cached] "s2_geography"
#>       @13ad07ce8 09 CHARSXP g0c1 [REF(79),gp=0x60,ATT] [ASCII] [cached] "wk_vctr"
data <- serialize(p, NULL)

p <- unserialize(data)
.Internal(inspect(p))
#> @12b2da4e8 19 VECSXP g0c1 [OBJ,REF(2),ATT] (len=1, tl=0)
#>   @12b2e6670 22 EXTPTRSXP g0c0 [REF(2)] <0x0>
#> ATTRIB:
#>   @12b2e6638 02 LISTSXP g0c0 [REF(1)] 
#>     TAG: @15a0111d0 01 SYMSXP g1c0 [MARK,REF(33812),LCK,gp=0x6000] "class" (has value)
#>     @15aebac88 16 STRSXP g0c2 [REF(1)] (len=2, tl=0)
#>       @13bb1a348 09 CHARSXP g1c2 [MARK,REF(131),gp=0x61,ATT] [ASCII] [cached] "s2_geography"
#>       @13ad07ce8 09 CHARSXP g0c1 [REF(80),gp=0x60,ATT] [ASCII] [cached] "wk_vctr"

Created on 2024-07-12 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions