JCMais / node-libcurl

libcurl bindings for Node.js
https://npmjs.org/package/node-libcurl
MIT License
666 stars 118 forks source link

Segmentation fault on sftp upload #383

Closed deadbeef84 closed 1 year ago

deadbeef84 commented 1 year ago

Describe the bug

Uploading to sftp causes segmentation fault.

To Reproduce

Run SFTP server using docker: docker run -v /tmp:/home/foo -p 2222:22 -it atmoz/sftp foo:pass:::upload

Upload file:

import fs from 'fs'
import { Curl } from 'node-libcurl'

const curl = new Curl()

curl.setOpt(Curl.option.URL, 'sftp://foo:pass@localhost:2222/upload/foo.bin')
curl.setOpt(Curl.option.SSL_VERIFYPEER, 0)
curl.setOpt(Curl.option.SSL_VERIFYHOST, 0)

curl.setOpt(Curl.option.UPLOAD, true)
curl.setUploadStream(fs.createReadStream('test.mp4'))

await new Promise((resolve, reject) => {
  console.log('starting request')
  curl
    .on('error', (err, code) => {
      console.log('ERROR', code, err)
      reject(err)
    })
    .on('end', (code, data, headers) => {
      console.log('end', code, headers, data)
      resolve()
    })
    .perform()
})
console.log('request done')

Version information:

Version:

Version: libcurl/7.74.0 OpenSSL/3.0.0g zlib/1.2.13 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.43.0 librtmp/2.3
Protocols: dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Features: AsynchDNS, IDN, IPv6, Largefile, GSS-API, Kerberos, SPNEGO, NTLM, NTLM_WB, SSL, libz, brotli, TLS-SRP, HTTP2, UnixSockets, HTTPS-proxy, PSL, alt-svc

OS: Linux / docker (base image node:18.13.0) Node.js Version: v18.13.0

Additional context

Debugging with GDB:

Thread 1 "node" received signal SIGSEGV, Segmentation fault.
0x0000000001c9c72d in nghttp2_map_find ()
(gdb) bt
#0  0x0000000001c9c72d in nghttp2_map_find ()
#1  0x0000000001c85a29 in nghttp2_session_get_stream ()
#2  0x0000000001c923d7 in nghttp2_session_set_local_window_size ()
#3  0x00007f40b03cf6a3 in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#4  0x00007f40b03b6222 in curl_easy_pause () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#5  0x00007f40b04502c7 in NodeLibcurl::Easy::Pause(Nan::FunctionCallbackInfo<v8::Value> const&) () from /usr/src/app/node_modules/node-libcurl/lib/binding/node_libcurl.node
#6  0x00007f40b045a47f in Nan::imp::FunctionCallbackWrapper(v8::FunctionCallbackInfo<v8::Value> const&) () from /usr/src/app/node_modules/node-libcurl/lib/binding/node_libcurl.node
#7  0x0000000000db0230 in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) ()
#8  0x0000000000db176f in v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) ()
#9  0x00000000016ef579 in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit ()
#10 0x00000000016734d0 in Builtins_InterpreterEntryTrampoline ()
#11 0x00002b7c35f815b9 in ?? ()
#12 0x00000b7113183dd9 in ?? ()
#13 0x0000000600000000 in ?? ()
#14 0x00002b7c35f81689 in ?? ()
#15 0x00002b4476ca6e41 in ?? ()
#16 0x0000000000000000 in ?? ()
deadbeef84 commented 1 year ago

Realized I was running version 2.3.4, it doesn't segfault on 3.0.0.

JCMais commented 1 year ago

thanks for the update @deadbeef84, did you find any other issues with v3.0.0 or can I mark this as resolved?

deadbeef84 commented 1 year ago

No other issues :+1: