Skip to content

foverlaps segfault when y has 0 rows #7597

Description

@nextpagesoft

Overview

Function fovelaps errors out with

 *** caught segfault ***
address 0xfffffffffffffffd, cause 'memory not mapped'

Traceback:
 1: foverlaps(x, y, by.x, by.y, )

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 1
R is aborting now ...

when y is a data.table with 0 rows. This happens in the official 1.18.0 version available on CRAN and the latest development version available on GitHub as of 15/01/2026.

Minimal reproducible example

library(data.table)
x <- data.table(Id = "A", StartX = 1L, EndX = 2L)
y <- data.table(Id = character(), StartY = integer(), EndY = integer())
by.x <- c("Id", "StartX", "EndX")
by.y <- c("Id", "StartY", "EndY")
setkeyv(y, by.y)
foverlaps(x, y, by.x, by.y)

Version 1.17.0 on the other hand produces:

> foverlaps(x, y, by.x, by.y)
       Id StartY  EndY StartX  EndX
   <char>  <int> <int>  <int> <int>
1:      A     NA    NA      1     2

Output of sessionInfo()

> sessionInfo()
R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

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

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
[1] data.table_1.18.99

loaded via a namespace (and not attached):
[1] compiler_4.5.2

Activity

  1. added theissue type on Jan 15, 2026
  2. added this to the 1.18.2 milestone on Jan 15, 2026
  3. aitap commented on Jan 15, 2026

    @aitap
    Member

    Thank you for the report! Indeed, the pointer dereferenced here

    totlen += count[k-1];

    originates from 0x1, which is what R now returns as the data pointer for empty vectors:

    ijoin.c:293:26: runtime error: pointer index expression with base 0x000000000001 overflowed to 0xfffffffffffffffd
    ijoin.c:293:26: runtime error: load of misaligned address 0xfffffffffffffffd for type 'int', which requires 4 byte alignment
    

    int *count = INTEGER(VECTOR_ELT(ux, uxcols-2));

    1.17.0 and 1.16.0 are actually broken too, older versions of R just didn't return a poisoned data pointer for empty vectors until 4.5.0.

  4. nextpagesoft commented on Jan 15, 2026

    @nextpagesoft
    Author

    Thank you, correct, I forgot the fact that I checked version 1.17.0 on R 4.4.3,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions