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

segfaults on R3.4.4 when i is NULL #4060

shrektan opened this issue Nov 19, 2019 · 1 comment · Fixed by #4067

segfaults on R3.4.4 when i is NULL #4060

shrektan opened this issue Nov 19, 2019 · 1 comment · Fixed by #4067


Copy link

@shrektan shrektan commented Nov 19, 2019

The following code causes segfauls on R3.4.4.

  1. Current it's reproducible on Windows. I haven't tested it on other platforms yet. UPDATE: I've reproduced this on Linux.
  2. Both the CRAN version and the dev version have this issue.
  3. Note, this happens only for R3.4.4 (or the previous version of R). On R3.5 or R3.6 it works fine So I doubt it relates to the code handles the ALTREP, which is introduced from R3.5. However, I'm not sure since I haven't digged into this.
tbl <- data.table(A = "a", key = "A")

Update: the segfault is triggered by Cbmerge and I confirm data.table v1.12.3 also has this issue.

@shrektan shrektan self-assigned this Nov 20, 2019
@shrektan shrektan added the bug label Nov 20, 2019
Copy link
Member Author

@shrektan shrektan commented Nov 20, 2019

It's cause by this line:

iN = ilen = anslen = LENGTH(VECTOR_ELT(i,0));

When i is NULL, it will be converted to zero column data.table() first. Since i is now a zero column data.table object, the VECTOR_ELT(i,0) doesn't exist and thus LENGTH(VECTOR_ELT(i,0)) returns garbage values.

I don't know why it can't happen in R3.5 or R3.6 but I will file a PR later anyway.

UPDATE: This is because the below code returns 0 on R3.5 or R3.6 but may be any garbage values on R3.4. I don't know the reason.

Rcpp::cppFunction("int getlength(SEXP x) { return LENGTH(VECTOR_ELT(x,0)); }")

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

Successfully merging a pull request may close this issue.

3 participants