rivermouth91
rivermouth91

Reputation: 29

R package fails to run examples on x64 but works on i386 and Debian

I’ve been having trouble loading a package onto CRAN. I am using R Studio to build my package and some lower-level C code for optimization. Within R Studio I'm able to load/build/check my package with no problems (I am using a Mac btw). However, when I build the package and submit it to CRAN, it's rejected with the following:

Flavor: r-devel-windows-ix86+x86_64
Check: running examples for arch 'x64', Result: ERROR

Upon looking at the log that is provided for me, the examples run perfectly fine for Debian and windows i386.

Does anyone have an idea as to why my examples fail for x64 but work fine on i386?

Below is the code in the 00check.log:

** running examples for arch 'i386' ... OK
** running examples for arch 'x64' ... ERROR
Running examples in 'fastcmprsk-Ex.R' failed
The error most likely occurred in:
.
.
.
> ### ** Examples
> 
> library(fastcmprsk)
> 
> set.seed(10)
> ftime <- rexp(200)
> fstatus <- sample(0:2, 200, replace = TRUE)
> cov <- matrix(runif(1000), nrow = 200)
> dimnames(cov)[[2]] <- c('x1','x2','x3','x4','x5')
> fit <- fastCrr(Crisk(ftime, fstatus) ~ cov, variance = FALSE)
* DONE
Status: 1 ERROR, 1 NOTE

I'm led to believe that the culprit is the fastCrr function. However, the example seems to have run fine for arch 'i386' (see above) and for Debian. I can't understand why it fails for x64, is there a hardware issue that I'm not aware of? The function I'm calling does call C for the optimization routine. Perhaps there's a leak somewhere but I double checked and made sure that I Free every Calloc variable. I'm not sure how else leaks can happen or why it'll only be specific to one system and not the other.

Hope this helps.

Thank you to all who've been viewing this and for your feedback.

Upvotes: 0

Views: 418

Answers (1)

Ralf Stubner
Ralf Stubner

Reputation: 26823

Using the wch1/r-debug docker image I have run UBSAN tools on your code. The ones from gcc found something:

ralf@barra:~$ docker run --rm -it wch1/r-debug
root@9131acbabe1f:/# git clone https://github.com/erickawaguchi/fastcmprsk
root@9131acbabe1f:/# cd fastcmprsk/
root@9131acbabe1f:/fastcmprsk# git checkout developer
root@9131acbabe1f:/fastcmprsk# cd -
root@9131acbabe1f:/# RDsan -e "install.packages(c('doParallel', 'dynpred', 'codetools', 'survival'))"
root@9131acbabe1f:/# RDsan CMD build fastcmprsk
root@9131acbabe1f:/# RDsan CMD check fastcmprsk_1.0.3.tar.gz 
[...]
==5515==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6180002383d0 at pc 0x7ff3b5ad8d3f bp 0x7ffebeb2bb90 sp 0x7ffebeb2bb80  
READ of size 4 at 0x6180002383d0 thread T0
    #0 0x7ff3b5ad8d3e in ccd_dense /fastcmprsk.Rcheck/00_pkg_src/fastcmprsk/src/denseFit.c:148

Indeed, at https://github.com/erickawaguchi/fastcmprsk/blob/319138af6dfe5414608a89dbb168ea1e0ab1a797/src/denseFit.c#L148 you are reading from ici past the array boundary, since the test i == (n - 1) is evaluated after the test ici[i + 1] != 1. I would start there, even though I am not sure why this leads to a deterministic failure on x64 Windows.

Upvotes: 1

Related Questions