V8 icon indicating copy to clipboard operation
V8 copied to clipboard

Double free crash with uncaught exceptions on CRAN's fedora-clang platform

Open glin opened this issue 2 years ago • 5 comments

Splitting this out from #128:

I just had to fix a really tough double free crash on CRAN's fedora-clang platform with my V8-using package too. Maybe it's the same issue, or related, or at least helpful in some way.

For whatever reason, the double free error was being caused by an uncaught exception in V8 there. To reproduce, you can use R-hub's fedora-clang-devel image (Fedora 33 and a bit behind CRAN, but still works). Install V8 using g++, not clang, as CRAN does, and then throw any error in V8 like throw new Error().

docker run -it --rm rhub/fedora-clang-devel

dnf install -y v8-devel

# Compile V8 with g++ as CRAN does - there's probably a better way to do this
cp ~/.R/Makevars ~/.R/Makevars.bk
echo 'CXX17=g++' >> ~/.R/Makevars
/opt/R-devel/bin/R -e 'options(repos = "https://cloud.r-project.org"); install.packages("V8")'
mv -f ~/.R/Makevars.bk ~/.R/Makevars

/opt/R-devel/bin/R -e 'ctx <- V8::new_context(); ctx$eval("throw new Error()")'
# > ctx <- V8::new_context(); ctx$eval("throw new Error()")
# free(): double free detected in tcache 2
# Aborted (core dumped)

My package was throwing an error to detect the broken V8 package on Fedora <= 36 (https://github.com/jeroen/V8/issues/65) to skip some tests, and hitting this crash. My sketchy workaround was to try and test for this in a separate R process like:

code <- "V8::new_context()$eval('not_defined')"
output <- suppressWarnings(
  system2(R.home("bin/R"), c("-e", shQuote(code)), stdout = TRUE, stderr = TRUE)
)
if (attr(output, "status") > 0 && !grepl("ReferenceError", paste(output, collapse = "\n"))) {
  # Then skip any tests that may throw uncaught exceptions
}

@jeroen:

I think this is a separate issue that is caused by an ABI incompatibility between libcxx (used by R) and libstdc++ (used by Fedora to compile v8-devel).

glin avatar Jan 08 '23 22:01 glin