Skip to content

Instantly share code, notes, and snippets.

@vjcitn
Created October 11, 2024 11:55
Show Gist options
  • Save vjcitn/c4c4e99314f0d77d58148b7d19cbedae to your computer and use it in GitHub Desktop.
Save vjcitn/c4c4e99314f0d77d58148b7d19cbedae to your computer and use it in GitHub Desktop.
triggers segfault on ubuntu 24.04 under R 4.4.1, when compiled with rmarkdown::render
---
title: "Triggers a curl/httr segfault during R CMD build"
author: Hervé Pagès
output:
BiocStyle::html_document:
toc: true
toc_depth: 2
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
This vignette triggers a curl segfault when built with
`R CMD build curlminitest` on Ubuntu 24.04 and Intel Mac.
The segfault typically occurs inside `curl::curl_fetch_disk()`.
```{r}
library(httr)
url1 <- "https://en.wikipedia.org/wiki/Bioconductor"
response1 <- GET(url1)
url2 <- "ftp://ftp.ensembl.org/pub/release-71/gtf/caenorhabditis_elegans/Caenorhabditis_elegans.WBcel235.71.gtf.gz"
response2a <- GET(url2, write_disk(tempfile()))
response2b <- GET(url2, write_disk(tempfile()))
```
@vjcitn
Copy link
Author

vjcitn commented Oct 11, 2024

under R -d gdb

> render("curlminitest.Rmd")
[Detaching after vfork from child process 91778]
[Detaching after vfork from child process 91780]

Attaching package: ‘BiocStyle’

The following objects are masked from ‘package:rmarkdown’:

    html_document, md_document, pdf_document

Downloading separate debug info for /lib/x86_64-linux-gnu/libuuid.so.1
                                                                                                                                              

processing file: curlminitest.Rmd
  |...................................                 |  67% [unnamed-chunk-1]Downloading separate debug info for /lib/x86_64-linux-gnu/libss
l.so.3
Downloading separate debug info for /lib/x86_64-linux-gnu/libcrypto.so.3                                                                      
Downloading separate debug info for /lib/x86_64-linux-gnu/libzstd.so.1                                                                        
Downloading separate debug info for /lib/x86_64-linux-gnu/libgnutls.so.30                                                                     
Downloading separate debug info for /lib/x86_64-linux-gnu/libhogweed.so.6                                                                     
Downloading separate debug info for /lib/x86_64-linux-gnu/libnettle.so.8                                                                      
Downloading separate debug info for /lib/x86_64-linux-gnu/libcom_err.so.2                                                                     
Downloading separate debug info for /lib/x86_64-linux-gnu/libsasl2.so.2                                                                       
Downloading separate debug info for /lib/x86_64-linux-gnu/libp11-kit.so.0                                                                     
[New Thread 0x7fffed4006c0 (LWP 91786)]                                                                                                       
[Thread 0x7fffed4006c0 (LWP 91786) exited]
[New Thread 0x7fffed4006c0 (LWP 91787)]
[Thread 0x7fffed4006c0 (LWP 91787) exited]
free(): invalid size

Thread 1 "R" received signal SIGABRT, Aborted.
Download failed: Invalid argument.  Continuing without source file ./nptl/./nptl/pthread_kill.c.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
warning: 44./nptl/pthread_kill.c: No such file or directory
(gdb) where
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff764526e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff76288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff76297b6 in __libc_message_impl (fmt=fmt@entry=0x7ffff77ce8d7 "%s\n") at ../sysdeps/posix/libc_fatal.c:132
#6  0x00007ffff76a8fe5 in malloc_printerr (str=str@entry=0x7ffff77cc68a "free(): invalid size") at ./malloc/malloc.c:5772
#7  0x00007ffff76ab38c in _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at ./malloc/malloc.c:4511
#8  0x00007ffff76add9e in __GI___libc_free (mem=0x555559051540) at ./malloc/malloc.c:3398
#9  0x00007fffeea832dc in chunk_list_free (anchor=0x555559071d68) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/bufq.c:153
#10 Curl_bufq_free (q=0x555559071d68) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/bufq.c:244
#11 0x00007fffeeb024d9 in http2_data_done.isra.0 (cf=0x5555556f2850, data=0x555558c14c60, premature=<optimized out>)
    at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/http2.c:326
#12 0x00007fffeeaaab63 in cf_h2_cntrl (cf=0x5555556f2850, data=0x555558c14c60, event=<optimized out>, arg1=<optimized out>, 
    arg2=<optimized out>) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/http2.c:2489
#13 0x00007fffeeaf880e in Curl_conn_cf_cntrl (arg2=0x0, arg1=0, event=2, ignore_result=<optimized out>, data=0x555558c14c60, 
    cf=0x5555556f2850) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/cfilters.c:501
#14 cf_cntrl_all.constprop.0 (conn=conn@entry=0x555558702200, data=data@entry=0x555558c14c60, ignore_result=ignore_result@entry=true, 
    event=event@entry=2, arg1=arg1@entry=0, arg2=0x0) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/cfilters.c:551
#15 0x00007fffeeae63d4 in Curl_conn_ev_data_detach (data=0x555558c14c60, conn=0x555558702200)
    at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/cfilters.c:568
#16 Curl_detach_connection (data=<optimized out>) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/multi.c:972
#17 extract_if_dead (conn=conn@entry=0x555558702200, data=0x555558c14c60) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/url.c:819
#18 0x00007fffeeae651c in call_extract_if_dead (data=<optimized out>, conn=0x555558702200, param=0x7fffffff0670)
    at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/url.c:845
#19 0x00007fffeea87d4d in Curl_conncache_foreach (data=0x555558c14c60, connc=<optimized out>, param=0x7fffffff0670, 
    func=0x7fffeeae6500 <call_extract_if_dead>) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/conncache.c:332
#20 0x00007fffeeac9bd9 in prune_dead_connections (data=0x555558c14c60) at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/url.c:874
#21 create_conn (async=0x7fffffff064f, in_connect=<synthetic pointer>, data=<optimized out>)
    at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/url.c:3623
#22 Curl_connect (protocol_done=0x7fffffff0650, asyncp=0x7fffffff064f, data=<optimized out>)
    at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/url.c:3889
#23 multi_runsingle (multi=multi@entry=0x5555560e2670, nowp=nowp@entry=0x7fffffff0710, data=data@entry=0x555558c14c60)
    at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/multi.c:1924
#24 0x00007fffeeaca0d5 in curl_multi_perform (multi=0x5555560e2670, running_handles=running_handles@entry=0x7fffffff0810)
    at /build/curl-ZfTNv6/curl-8.5.0/debian/build/lib/multi.c:2702
#25 0x00007fffeeb4769b in curl_perform_with_interrupt (handle=0x555558c14c60) at interrupt.c:47
#26 0x00007fffeeb45515 in R_curl_fetch_disk (url=<optimized out>, ptr=0x5555574f9c88, path=0x555556fb2200, mode=0x555558155c00, 
    nonblocking=0x555555574810) at fetch.c:79
#27 0x00007ffff7b051de in R_doDotCall (fun=fun@entry=0x7fffeeb45390 <R_curl_fetch_disk>, nargs=nargs@entry=5, 
    cargs=cargs@entry=0x7fffffff13c0, call=call@entry=0x55555759d238) at dotcode.c:766
#28 0x00007ffff7b488a0 in bcEval_loop (ploc=ploc@entry=0x7fffffff1680) at eval.c:8691
#29 0x00007ffff7b5c3aa in bcEval (rho=0x555557945260, body=0x55555759ece8) at eval.c:7524
#30 bcEval (body=0x55555759ece8, rho=0x555557945260) at eval.c:7509
#31 0x00007ffff7b5c71b in Rf_eval (e=e@entry=0x55555759ece8, rho=rho@entry=0x555557945260) at eval.c:1167
#32 0x00007ffff7b5e93f in R_execClosure (call=call@entry=0x555557945340, newrho=newrho@entry=0x555557945260, sysparent=<optimized out>, 
    rho=rho@entry=0x555557945810, arglist=arglist@entry=0x5555579459d0, op=op@entry=0x55555759b3c0) at eval.c:2398
#33 0x00007ffff7b5f787 in applyClosure_core (call=0x555557945340, op=0x55555759b3c0, arglist=0x5555579459d0, rho=0x555557945810, 
    suppliedvars=<optimized out>, unpromise=unpromise@entry=FALSE) at eval.c:2311
#34 0x00007ffff7b601ad in Rf_applyClosure (call=<optimized out>, op=<optimized out>, arglist=<optimized out>, rho=<optimized out>, 
    suppliedvars=<optimized out>, unpromise=unpromise@entry=FALSE) at eval.c:2333
#35 0x00007ffff7ba5256 in applyMethod (call=call@entry=0x555557945340, op=op@entry=0x55555759b3c0, args=<optimized out>, 
    rho=rho@entry=0x555557945810, newvars=newvars@entry=0x555557945420) at objects.c:120
#36 0x00007ffff7ba6406 in dispatchMethod (op=op@entry=0x555555820e10, sxp=0x55555759b3c0, dotClass=dotClass@entry=0x555558e5dc08, 
    cptr=cptr@entry=0x7ffff420cde0, method=method@entry=0x555557b0d8f8, generic=generic@entry=0x555558fe5e68 "request_fetch", 
    rho=<optimized out>, callrho=<optimized out>, defrho=<optimized out>) at objects.c:472
#37 0x00007ffff7ba6b09 in Rf_usemethod (generic=0x555558fe5e68 "request_fetch", obj=obj@entry=0x555558e5da88, 
    call=call@entry=0x555555820748, args=args@entry=0x5555555728f0, rho=rho@entry=0x555557945810, callrho=callrho@entry=0x555557912688, 
    defrho=0x555557a60218, ans=0x7fffffff3dc8) at objects.c:512
#38 0x00007ffff7ba6e04 in do_usemethod (call=0x555555820748, op=<optimized out>, args=<optimized out>, env=0x555557945810) at objects.c:578
#39 0x00007ffff7b4222c in bcEval_loop (ploc=ploc@entry=0x7fffffff4ff0) at eval.c:7172
#40 0x00007ffff7b5c3aa in bcEval (rho=0x55555771f888, body=0x555557cae708) at eval.c:7524
#41 bcEval (body=0x555557cae708, rho=0x55555771f888) at eval.c:7509
#42 0x00007ffff7b5c71b in Rf_eval (e=e@entry=0x555557cae708, rho=rho@entry=0x55555771f888) at eval.c:1167
#43 0x00007ffff7b5e93f in R_execClosure (call=call@entry=0x5555579871f8, newrho=newrho@entry=0x55555771f888, sysparent=<optimized out>, 
    rho=rho@entry=0x5555555a9bf8, arglist=arglist@entry=0x55555771fa10, op=op@entry=0x555557ca9fb0) at eval.c:2398
#44 0x00007ffff7b5f787 in applyClosure_core (call=call@entry=0x5555579871f8, op=op@entry=0x555557ca9fb0, arglist=0x55555771fa10, 
    rho=rho@entry=0x5555555a9bf8, suppliedvars=<optimized out>, unpromise=unpromise@entry=TRUE) at eval.c:2311
#45 0x00007ffff7b5c856 in Rf_applyClosure (unpromise=TRUE, suppliedvars=<optimized out>, rho=0x5555555a9bf8, arglist=<optimized out>, 
    op=0x555557ca9fb0, call=0x5555579871f8) at eval.c:2333
#46 Rf_eval (e=0x5555579871f8, rho=rho@entry=0x5555555a9bf8) at eval.c:1285
#47 0x00007ffff7b619a4 in do_set (call=0x555557987038, op=0x555555570a18, args=0x555557987070, rho=0x5555555a9bf8)
    at ../../src/include/Rinlinedfuns.h:90
#48 0x00007ffff7b5cb50 in Rf_eval (e=<optimized out>, rho=0x5555555a9bf8) at eval.c:1237
#49 0x00007ffff7b62df2 in do_eval (call=<optimized out>, op=0x555555591bc8, args=0x55555771fb98, rho=0x55555771fc08) at eval.c:3956
#50 0x00007ffff7b42409 in bcEval_loop (ploc=ploc@entry=0x7fffffff6ad0) at eval.c:8141
#51 0x00007ffff7b5c3aa in bcEval (rho=0x555557334228, body=0x555557335568) at eval.c:7524

@vjcitn
Copy link
Author

vjcitn commented Oct 11, 2024

Without gdb we see

> rmarkdown::render("curlminitest.Rmd")


processing file: curlminitest.Rmd
  |...................................                 |  67% [unnamed-chunk-1]
 *** caught segfault ***
address (nil), cause 'unknown'

Traceback:
 1: curl::curl_fetch_disk(url, x$path, handle = handle)
 2: request_fetch.write_disk(req$output, req$url, handle)
 3: request_fetch(req$output, req$url, handle)
 4: request_perform(req, hu$handle$handle)
 5: GET(url2, write_disk(tempfile()))
 6: eval(expr, envir)
 7: eval(expr, envir)
 8: withVisible(eval(expr, envir))
 9: withCallingHandlers(code, message = function (cnd) {    watcher$capture_plot_and_output()    if (on_message$capture) {        watcher$push
(cnd)    }    if (on_message$silence) {        invokeRestart("muffleMessage")    }}, warning = function (cnd) {    if (getOption("warn") >= 2 
|| getOption("warn") < 0) {        return()    }    watcher$capture_plot_and_output()    if (on_warning$capture) {        cnd <- sanitize_call
(cnd)        watcher$push(cnd)    }    if (on_warning$silence) {        invokeRestart("muffleWarning")    }}, error = function (cnd) {    watc
her$capture_plot_and_output()    cnd <- sanitize_call(cnd)    watcher$push(cnd)    switch(on_error, continue = invokeRestart("eval_continue"),
         stop = invokeRestart("eval_stop"), error = invokeRestart("eval_error",             cnd))})
10: eval(call)
11: eval(call)
12: with_handlers({    for (expr in tle$exprs) {        ev <- withVisible(eval(expr, envir))        watcher$capture_plot_and_output()        w
atcher$print_value(ev$value, ev$visible, envir)    }    TRUE}, handlers)
13: doWithOneRestart(return(expr), restart)
14: withOneRestart(expr, restarts[[1L]])

@vjcitn
Copy link
Author

vjcitn commented Oct 11, 2024

> sessionInfo()
R version 4.4.1 Patched (2024-09-30 r87215)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS

Matrix products: default
BLAS:   /usr/local/lib/R/lib/libRblas.so 
LAPACK: /usr/local/lib/R/lib/libRlapack.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] httr_1.4.7       BiocStyle_2.32.1

loaded via a namespace (and not attached):
 [1] digest_0.6.37       R6_2.5.1            bookdown_0.40      
 [4] fastmap_1.2.0       xfun_0.48           cachem_1.1.0       
 [7] knitr_1.48          htmltools_0.5.8.1   rmarkdown_2.28     
[10] lifecycle_1.0.4     cli_3.6.3           sass_0.4.9         
[13] jquerylib_0.1.4     compiler_4.4.1      tools_4.4.1        
[16] curl_5.2.3          evaluate_1.0.1      bslib_0.8.0        
[19] yaml_2.3.10         BiocManager_1.30.25 jsonlite_1.8.9     
[22] rlang_1.1.4   

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