Henrik Bengtsson (max 7Mb)
2006-Apr-26 17:35 UTC
[Rd] Large number of linked environments makes save() crash R
Hi, first, this not a problem originating from me, but it was observed trying to do similar things with my R.oo package, so I troubleshooted it and found the following. On R v2.3.0 (patched), the following will crash R on WinXP sooner or later: troubleLimit <- 20435; linkedList <- list(head=new.env()); currEnv <- linkedList$head; for (kk in 1:(2*troubleLimit)) { if (kk %% 100 == 0) print(kk); nextEnv <- new.env(); assign("nxt", nextEnv, envir=currEnv); currEnv <- nextEnv; if (kk > troubleLimit) { cat("Saving linked list of length ", kk, "...", sep=""); save(linkedList, file="linkedList.RData"); cat("ok\n"); } } This gives: ... [1] 20300 [1] 20400 Saving linked list of length 20436...ok Saving linked list of length 20437...ok Saving linked list of length 20438... and then R crashes/terminates. On my WinXP machine it always happens at the same number of environments. I tried the same on R v2.2.0 (sic!) on Unix and there it gave a segfault a bit after 10000 environments. ...and, the purpose of the example is not to implement linked lists, it to show that you can torture R to crash. Cheers Henrik
Prof Brian Ripley
2006-Apr-26 19:09 UTC
[Rd] Large number of linked environments makes save() crash R
I think this is a C stack overflow problem. Probably needs a test added internally to save(). I could not reproduce this on Linux: I got a C stack overflow that was caught. On Wed, 26 Apr 2006, Henrik Bengtsson (max 7Mb) wrote:> Hi, > > first, this not a problem originating from me, but it was observed > trying to do similar things with my R.oo package, so I troubleshooted > it and found the following. > > On R v2.3.0 (patched), the following will crash R on WinXP sooner or later: > > troubleLimit <- 20435; > > linkedList <- list(head=new.env()); > > currEnv <- linkedList$head; > for (kk in 1:(2*troubleLimit)) { > if (kk %% 100 == 0) > print(kk); > nextEnv <- new.env(); > assign("nxt", nextEnv, envir=currEnv); > currEnv <- nextEnv; > if (kk > troubleLimit) { > cat("Saving linked list of length ", kk, "...", sep=""); > save(linkedList, file="linkedList.RData"); > cat("ok\n"); > } > } > > This gives: > ... > [1] 20300 > [1] 20400 > Saving linked list of length 20436...ok > Saving linked list of length 20437...ok > Saving linked list of length 20438... > > and then R crashes/terminates. On my WinXP machine it always happens > at the same number of environments. > > I tried the same on R v2.2.0 (sic!) on Unix and there it gave a > segfault a bit after 10000 environments. ...and, the purpose of the > example is not to implement linked lists, it to show that you can > torture R to crash. > > Cheers > > Henrik > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >-- 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