[R-SIG-Mac] Segfault with rWishart in R 2.15.1

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jul 4 10:05:59 CEST 2012


It's not a Mac issue (except perhaps the crash).

The author of rWishart used alloca() without checking if there is space 
available on the stack.  For large enough arrays that blows the stack 
and although R can tell you that has happened, the damage has been done.

We'll fix that shortly, so take a look at a nightly build of R-patched 
in a couple of days.

On 04/07/2012 02:12, Michael Braun wrote:
> I just upgraded to R 2.15.1, and I am getting a segmentation fault when using the rWishart function (from the stats package) to sample moderately-size matrices.
>
> Here is the output when I run R within gdb.  720 appears to be the dimensionality cut-off.  Anything smaller works fine.  Anything larger crashes.
>
>> x=rWishart(1,700,diag(700)) // this works
>> x=rWishart(1,720,diag(720))
> Error: C stack usage is too close to the limit
>> x=rWishart(1,722,diag(722))
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_PROTECTION_FAILURE at address: 0x00007fff5f3fff88
> 0x00007fff88b9c68b in __vfprintf ()
> (gdb) bt
> #0  0x00007fff88b9c68b in __vfprintf ()
> #1  0x00007fff88b9c18e in vfprintf_l ()
> #2  0x00007fff88ba52d0 in printf ()
> #3  0x0000000100198619 in Rstd_WriteConsoleEx (
>      buf=<value temporarily unavailable, due to optimizations>,
>      len=<value temporarily unavailable, due to optimizations>,
>      otype=<value temporarily unavailable, due to optimizations>)
>      at ../../../../R-2.15.1/src/unix/sys-std.c:963
> #4  0x00000001001497b7 in REvprintf (format=0x100253820 "%s",
>      arg=0x7fff5f4029f0) at ../../../../R-2.15.1/src/main/printutils.c:813
> #5  0x0000000100149a02 in REprintf (
>      format=<value temporarily unavailable, due to optimizations>)
>      at ../../../../R-2.15.1/src/main/printutils.c:698
> #6  0x0000000100099e45 in verrorcall_dflt (call=0x10080db78,
>      format=0x10025b9d8 "C stack usage is too close to the limit",
>      ap=0x7fff5f408cc0) at ../../../../R-2.15.1/src/main/errors.c:656
> #7  0x000000010009a86e in Rf_errorcall (call=0x10080db78,
>      format=0x10025b9d8 "C stack usage is too close to the limit")
>      at ../../../../R-2.15.1/src/main/errors.c:698
> #8  0x000000010009c95c in R_CheckStack ()
>      at ../../../../R-2.15.1/src/main/errors.c:93
> #9  0x0000000102704e80 in R_rWishart ()
> #10 0x000000010007af0c in do_dotcall (call=0x102f63710,
> ---Type <return> to continue, or q <return> to quit---
>      op=<value temporarily unavailable, due to optimizations>,
>      args=<value temporarily unavailable, due to optimizations>,
>      env=<value temporarily unavailable, due to optimizations>)
>      at ../../../../R-2.15.1/src/main/dotcode.c:543
> #11 0x00000001000a128f in bcEval (
>      body=<value temporarily unavailable, due to optimizations>,
>      rho=0x103df1140,
>      useCache=<value temporarily unavailable, due to optimizations>)
>      at ../../../../R-2.15.1/src/main/eval.c:4442
> #12 0x00000001000aa1f5 in Rf_eval (e=0x102f63748, rho=0x103df1140)
>      at ../../../../R-2.15.1/src/main/eval.c:397
> #13 0x00000001000af5d1 in Rf_applyClosure (call=0x103df0b58, op=0x102f62470,
>      arglist=0x103df0df8, rho=0x10085b6a8, suppliedenv=0x10085b6e0)
>      at ../../../../R-2.15.1/src/main/eval.c:859
> #14 0x00000001000aa402 in Rf_eval (e=0x103df0b58, rho=0x10085b6a8)
>      at ../../../../R-2.15.1/src/main/eval.c:510
> #15 0x00000001000ad705 in do_set (call=0x103df0c38, op=0x100832030,
>      args=0x103df0c00, rho=0x10085b6a8)
>      at ../../../../R-2.15.1/src/main/eval.c:1715
> #16 0x00000001000aa4ec in Rf_eval (e=0x103df0c38, rho=0x10085b6a8)
>      at ../../../../R-2.15.1/src/main/eval.c:466
> #17 0x00000001000e3822 in Rf_ReplIteration (rho=0x10085b6a8, savestack=0,
>      browselevel=<value temporarily unavailable, due to optimizations>,
> ---Type <return> to continue, or q <return> to quit---
>      state=0x7fff5fbfe7d0) at ../../../../R-2.15.1/src/main/main.c:256
> #18 0x00000001000e3b11 in R_ReplConsole (rho=0x10085b6a8, savestack=0,
>      browselevel=0) at ../../../../R-2.15.1/src/main/main.c:305
> #19 0x00000001000e4020 in run_Rmainloop ()
>      at ../../../../R-2.15.1/src/main/main.c:987
> #20 0x0000000100000eeb in main ()
>
> Here is my sessionInfo() output.  I am running R on a brand new (as in, yesterday) Macbook Pro.  This is the CRAN binary version.  I did not link to an optimized BLAS on this computer (yet).  However, I did try this on my office computer (Mac Pro) that I compiled from source, linking to Intel MKL, and that also crashes around k=722.
>
>> sessionInfo()
> R version 2.15.1 (2012-06-22)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>
> Anyway, since R is segfaulting on a brand new computer, I thought you would like to know.
>
> Michael=
>
>
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-SIG-Mac mailing list