savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.39k stars 128 forks source link

Lame encoder causes segfault #3936

Open vitoyucepi opened 3 months ago

vitoyucepi commented 3 months ago

Describe the bug Encoding with %mp3 causes a segfault when using ocaml 5 in alpine.

Liquidsoap log ``` 2024/05/23 19:55:30 >>> LOG START 2024/05/23 19:55:29 [main:3] Liquidsoap 2.2.5+dev 2024/05/23 19:55:29 [main:3] Using: angstrom=0.16.0 bigstringaf=0.9.1 bytes=[distributed with OCaml 4.02 or above] camlp-streams camomile.lib=2.0 cry=1.0.3 curl=0.9.2 dtools=0.4.5 dune-build-info=3.15.2 dune-private-libs.dune-section=3.15.2 dune-site=3.15.2 dune-site.private=3.15.2 duppy=0.9.4 fileutils=0.6.4 gen=1.1 lame=0.3.7 liquidsoap-lang=2.2.5 liquidsoap-lang.console=2.2.5 liquidsoap_builtins liquidsoap_core liquidsoap_lame liquidsoap_mad liquidsoap_optionals liquidsoap_oss liquidsoap_runtime mad=0.5.3 magic-mime=1.3.1 menhirLib=20231231 metadata=0.3.0 mm=0.8.5 mm.audio=0.8.5 mm.base=0.8.5 mm.image=0.8.5 mm.midi=0.8.5 mm.video=0.8.5 pcre=7.5.0 re=1.11.0 sedlex=3.2 seq=[distributed with OCaml 4.07 or above] stdlib-shims=0.3.0 str=5.2.0 stringext=1.6.0 threads=5.2.0 unix=5.2.0 uri=4.4.0 2024/05/23 19:55:29 [clock:3] Using builtin (low-precision) implementation for latency control 2024/05/23 19:55:29 [main:3] Standard library loaded in 0.84 seconds. 2024/05/23 19:55:30 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz main. 2024/05/23 19:55:30 [frame:3] Video frame size set to: 1280x720 2024/05/23 19:55:30 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples. 2024/05/23 19:55:30 [frame:3] Targeting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks. 2024/05/23 19:55:30 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks. 2024/05/23 19:55:30 [sandbox:3] Sandboxing disabled 2024/05/23 19:55:30 [startup:3] Typechecking: 0.58s 2024/05/23 19:55:30 [startup:3] Evaluation: 0.01s 2024/05/23 19:55:30 [startup:3] Typechecking: 0.02s 2024/05/23 19:55:30 [startup:3] Evaluation: 0.00s 2024/05/23 19:55:30 [startup:3] Typechecking: 0.00s 2024/05/23 19:55:30 [startup:3] Evaluation: 0.00s 2024/05/23 19:55:30 [startup:3] Loaded /home/opam/main.liq: 0.00s 2024/05/23 19:55:30 [output_file:3] Content type is {audio=pcm(stereo)}. 2024/05/23 19:55:30 [sine:3] Content type is {audio=pcm(stereo)}. 2024/05/23 19:55:30 [video.converter:3] Couldn't find preferred video converter: ffmpeg. 2024/05/23 19:55:30 [audio.converter:3] Using samplerate converter: native. 2024/05/23 19:55:30 [video.text:3] Using native implementation 2024/05/23 19:55:30 [clock.main:3] Streaming loop starts in auto-sync mode 2024/05/23 19:55:30 [clock.main:3] Delegating synchronization to CPU clock ```
GDB dump ```gdb Thread 4 "liquidsoap" received signal SIGSEGV, Segmentation fault. 0x000065340914853d in ocaml_lame_encode_flush (l=135116102974104) at lame_stubs.c:306 Thread 8 (LWP 28 "liquidsoap"): #0 __cp_end () at src/thread/x86_64/syscall_cp.s:29 #1 0x00007ae33c3e94fc in __syscall_cp_c (nr=7, u=, v=, w=, x=, y=, z=0) at src/thread/pthread_cancel.c:33 #2 0x00007ae33c3db3db in poll (fds=fds@entry=0x7ae32af91e70, n=n@entry=4, timeout=timeout@entry=499) at src/select/poll.c:9 #3 0x0000653409157d75 in poll (__s=499, __n=4, __f=0x7ae32af91e70) at /usr/include/fortify/poll.h:40 #4 caml_poll (_read=, _write=, _err=, _timeout=) at duppy_stubs.c:95 #5 #6 0x000065340904be32 in camlDuppy.poll_596 () at src/duppy.ml:39 #7 0x000065340904d0ba in camlDuppy.f_1088 () at src/duppy.ml:213 #8 0x000065340904cc7e in camlDuppy.process_1078 () at src/duppy.ml:234 #9 0x000065340904dad9 in camlDuppy.run_1168 () at src/duppy.ml:339 #10 0x000065340904dcba in camlDuppy.f_1178 () at src/duppy.ml:360 #11 0x000065340904d890 in camlDuppy.queue_inner_3045 () at src/duppy.ml:370 #12 0x0000653408caed35 in camlTutils.process_1235 () at src/core/tools/tutils.ml:186 #13 0x000065340907a517 in camlThread.fun_768 () at thread.ml:48 #14 #15 0x0000653409176830 in caml_callback_exn (closure=, closure@entry=135116103660808, arg=, arg@entry=1) at runtime/callback.c:201 #16 0x000065340915952e in caml_thread_start (v=) at st_stubs.c:634 #17 0x00007ae33c3ea22e in start (p=0x7ae31f6b7ab8) at src/thread/pthread_create.c:207 #18 0x00007ae33c3ec82f in __clone () at src/thread/x86_64/clone.s:22 Backtrace stopped: frame did not save the PC Thread 7 (LWP 27 "liquidsoap"): #0 __cp_end () at src/thread/x86_64/syscall_cp.s:29 #1 0x00007ae33c3e94fc in __syscall_cp_c (nr=202, u=, v=, w=, x=, y=, z=0) at src/thread/pthread_cancel.c:33 #2 0x00007ae33c3e8a2e in __futex4_cp (to=, val=2, op=128, addr=0x7ae31f6e38a4) at src/thread/__timedwait.c:24 #3 __timedwait_cp (addr=addr@entry=0x7ae31f6e38a4, val=val@entry=2, clk=clk@entry=0, at=at@entry=0x0, priv=128, priv@entry=1) at src/thread/__timedwait.c:52 #4 0x00007ae33c3e9894 in __pthread_cond_timedwait (c=c@entry=0x7ae32af9b800, m=m@entry=0x7ae33bde1730, ts=ts@entry=0x0) at src/thread/pthread_cond_timedwait.c:100 #5 0x00007ae33c3e9e67 in pthread_cond_wait (c=c@entry=0x7ae32af9b800, m=m@entry=0x7ae33bde1730) at src/thread/pthread_cond_wait.c:5 #6 0x0000653409195dee in sync_condvar_wait (m=0x7ae33bde1730, c=0x7ae32af9b800) at runtime/sync_posix.h:122 #7 caml_ml_condition_wait (wcond=, wmut=) at runtime/sync.c:172 #8 #9 0x000065340904dbf5 in camlDuppy.run_1168 () at src/duppy.ml:354 #10 0x000065340904dcba in camlDuppy.f_1178 () at src/duppy.ml:360 #11 0x000065340904d890 in camlDuppy.queue_inner_3045 () at src/duppy.ml:370 #12 0x0000653408caed35 in camlTutils.process_1235 () at src/core/tools/tutils.ml:186 #13 0x000065340907a517 in camlThread.fun_768 () at thread.ml:48 #14 #15 0x0000653409176830 in caml_callback_exn (closure=, closure@entry=135116103662272, arg=, arg@entry=1) at runtime/callback.c:201 #16 0x000065340915952e in caml_thread_start (v=) at st_stubs.c:634 #17 0x00007ae33c3ea22e in start (p=0x7ae31f6e3ab8) at src/thread/pthread_create.c:207 #18 0x00007ae33c3ec82f in __clone () at src/thread/x86_64/clone.s:22 Backtrace stopped: frame did not save the PC Thread 6 (LWP 26 "liquidsoap"): #0 __cp_end () at src/thread/x86_64/syscall_cp.s:29 #1 0x00007ae33c3e94fc in __syscall_cp_c (nr=202, u=, v=, w=, x=, y=, z=0) at src/thread/pthread_cancel.c:33 #2 0x00007ae33c3e8a2e in __futex4_cp (to=, val=2, op=128, addr=0x7ae31f70f8a4) at src/thread/__timedwait.c:24 #3 __timedwait_cp (addr=addr@entry=0x7ae31f70f8a4, val=val@entry=2, clk=clk@entry=0, at=at@entry=0x0, priv=128, priv@entry=1) at src/thread/__timedwait.c:52 #4 0x00007ae33c3e9894 in __pthread_cond_timedwait (c=c@entry=0x7ae32af9b7c0, m=m@entry=0x7ae33bde1730, ts=ts@entry=0x0) at src/thread/pthread_cond_timedwait.c:100 #5 0x00007ae33c3e9e67 in pthread_cond_wait (c=c@entry=0x7ae32af9b7c0, m=m@entry=0x7ae33bde1730) at src/thread/pthread_cond_wait.c:5 #6 0x0000653409195dee in sync_condvar_wait (m=0x7ae33bde1730, c=0x7ae32af9b7c0) at runtime/sync_posix.h:122 #7 caml_ml_condition_wait (wcond=, wmut=) at runtime/sync.c:172 #8 #9 0x000065340904dbf5 in camlDuppy.run_1168 () at src/duppy.ml:354 #10 0x000065340904dcba in camlDuppy.f_1178 () at src/duppy.ml:360 #11 0x000065340904d890 in camlDuppy.queue_inner_3045 () at src/duppy.ml:370 #12 0x0000653408caed35 in camlTutils.process_1235 () at src/core/tools/tutils.ml:186 #13 0x000065340907a517 in camlThread.fun_768 () at thread.ml:48 #14 #15 0x0000653409176830 in caml_callback_exn (closure=, closure@entry=135116103663688, arg=, arg@entry=1) at runtime/callback.c:201 #16 0x000065340915952e in caml_thread_start (v=) at st_stubs.c:634 #17 0x00007ae33c3ea22e in start (p=0x7ae31f70fab8) at src/thread/pthread_create.c:207 #18 0x00007ae33c3ec82f in __clone () at src/thread/x86_64/clone.s:22 Backtrace stopped: frame did not save the PC Thread 5 (LWP 25 "liquidsoap"): #0 __cp_end () at src/thread/x86_64/syscall_cp.s:29 #1 0x00007ae33c3e94fc in __syscall_cp_c (nr=202, u=, v=, w=, x=, y=, z=0) at src/thread/pthread_cancel.c:33 #2 0x00007ae33c3e8a2e in __futex4_cp (to=, val=2, op=128, addr=0x7ae31f73b8a4) at src/thread/__timedwait.c:24 #3 __timedwait_cp (addr=addr@entry=0x7ae31f73b8a4, val=val@entry=2, clk=clk@entry=0, at=at@entry=0x0, priv=128, priv@entry=1) at src/thread/__timedwait.c:52 #4 0x00007ae33c3e9894 in __pthread_cond_timedwait (c=c@entry=0x7ae32af9b780, m=m@entry=0x7ae33bde1730, ts=ts@entry=0x0) at src/thread/pthread_cond_timedwait.c:100 #5 0x00007ae33c3e9e67 in pthread_cond_wait (c=c@entry=0x7ae32af9b780, m=m@entry=0x7ae33bde1730) at src/thread/pthread_cond_wait.c:5 #6 0x0000653409195dee in sync_condvar_wait (m=0x7ae33bde1730, c=0x7ae32af9b780) at runtime/sync_posix.h:122 #7 caml_ml_condition_wait (wcond=, wmut=) at runtime/sync.c:172 #8 #9 0x000065340904dbf5 in camlDuppy.run_1168 () at src/duppy.ml:354 #10 0x000065340904dcba in camlDuppy.f_1178 () at src/duppy.ml:360 #11 0x000065340904d890 in camlDuppy.queue_inner_3045 () at src/duppy.ml:370 #12 0x0000653408caed35 in camlTutils.process_1235 () at src/core/tools/tutils.ml:186 #13 0x000065340907a517 in camlThread.fun_768 () at thread.ml:48 #14 #15 0x0000653409176830 in caml_callback_exn (closure=, closure@entry=135116103665048, arg=, arg@entry=1) at runtime/callback.c:201 #16 0x000065340915952e in caml_thread_start (v=) at st_stubs.c:634 #17 0x00007ae33c3ea22e in start (p=0x7ae31f73bab8) at src/thread/pthread_create.c:207 #18 0x00007ae33c3ec82f in __clone () at src/thread/x86_64/clone.s:22 Backtrace stopped: frame did not save the PC Thread 4 (LWP 24 "liquidsoap"): #0 0x000065340914853d in ocaml_lame_encode_flush (l=135116102974104) at lame_stubs.c:306 #1 #2 camlLame_encoder.stop_1222 () at src/core/encoder/encoders/lame_encoder.ml:117 #3 0x0000653408cc4058 in camlEncoder.fun_2258 () at src/core/tools/tutils.ml:116 #4 0x0000653408d7d6a0 in camlIcecast2.fun_3378 () at src/core/outputs/icecast2.ml:644 #5 0x0000653408d7df3b in camlIcecast2.fun_3301 () at src/core/outputs/icecast2.ml:633 #6 0x0000653408d7e224 in camlIcecast2.fun_3252 () at src/core/outputs/icecast2.ml:550 #7 0x0000653408d0596d in camlOutput.f_2127 () at src/core/outputs/output.ml:256 #8 0x0000653408d05b3a in camlOutput.fun_2604 () at src/core/outputs/output.ml:267 #9 0x0000653408d033b3 in camlOutput.fun_2436 () at src/core/outputs/output.ml:192 #10 0x0000653408cd2107 in camlClock.fun_2451 () at src/core/clock.ml:318 #11 0x00006534090c407c in camlStdlib__List.fold_left_380 () at list.ml:123 #12 0x0000653408ccec7a in camlClock.fun_2397 () at src/core/clock.ml:315 #13 0x0000653408cd1dee in camlClock.loop_1229 () at src/core/clock.ml:277 #14 0x0000653408ccf2c5 in camlClock.fun_2355 () at src/core/clock.ml:280 #15 0x0000653408caed35 in camlTutils.process_1235 () at src/core/tools/tutils.ml:186 #16 0x000065340907a517 in camlThread.fun_768 () at thread.ml:48 #17 #18 0x0000653409176830 in caml_callback_exn (closure=, closure@entry=135116103666744, arg=, arg@entry=1) at runtime/callback.c:201 #19 0x000065340915952e in caml_thread_start (v=) at st_stubs.c:634 #20 0x00007ae33c3ea22e in start (p=0x7ae32a39dab8) at src/thread/pthread_create.c:207 #21 0x00007ae33c3ec82f in __clone () at src/thread/x86_64/clone.s:22 Backtrace stopped: frame did not save the PC Thread 3 (LWP 22 "liquidsoap"): #0 __cp_end () at src/thread/x86_64/syscall_cp.s:29 #1 0x00007ae33c3e94fc in __syscall_cp_c (nr=202, u=, v=, w=, x=, y=, z=0) at src/thread/pthread_cancel.c:33 #2 0x00007ae33c3e8a2e in __futex4_cp (to=, val=2, op=128, addr=0x7ae32a3c9844) at src/thread/__timedwait.c:24 #3 __timedwait_cp (addr=addr@entry=0x7ae32a3c9844, val=val@entry=2, clk=clk@entry=0, at=at@entry=0x0, priv=128, priv@entry=1) at src/thread/__timedwait.c:52 #4 0x00007ae33c3e9894 in __pthread_cond_timedwait (c=c@entry=0x65340975e9e8 , m=m@entry=0x65340975e9b0 , ts=ts@entry=0x0) at src/thread/pthread_cond_timedwait.c:100 #5 0x00007ae33c3e9e67 in pthread_cond_wait (c=c@entry=0x65340975e9e8 , m=m@entry=0x65340975e9b0 ) at src/thread/pthread_cond_wait.c:5 #6 0x0000653409158af0 in st_masterlock_acquire (m=0x65340975e9a8 ) at /home/abuild/.opam/ocaml-base-compiler.5.2.0/.opam-switch/build/ocaml-base-compiler.5.2.0/otherlibs/systhreads/st_pthreads.h :165 #7 0x0000653409158b61 in thread_lock_acquire (dom_id=) at st_stubs.c:127 #8 caml_thread_leave_blocking_section () at st_stubs.c:262 #9 0x0000653409193c96 in caml_leave_blocking_section () at runtime/signals.c:196 #10 0x0000653409195df5 in caml_ml_condition_wait (wcond=, wmut=) at runtime/sync.c:173 #11 #12 0x0000653409076eba in camlDtools__Dtools_impl.fun_2846 () at src/dtools_impl.ml:747 #13 0x0000653409076c49 in camlDtools__Dtools_impl.mutexify_1614 () at src/dtools_impl.ml:715 #14 0x0000653409076e4e in camlDtools__Dtools_impl.f_1634 () at src/dtools_impl.ml:743 #15 0x000065340907a517 in camlThread.fun_768 () at thread.ml:48 #16 #17 0x0000653409176830 in caml_callback_exn (closure=, closure@entry=135116103808856, arg=, arg@entry=1) at runtime/callback.c:201 #18 0x000065340915952e in caml_thread_start (v=) at st_stubs.c:634 #19 0x00007ae33c3ea22e in start (p=0x7ae32a3c9ab8) at src/thread/pthread_create.c:207 #20 0x00007ae33c3ec82f in __clone () at src/thread/x86_64/clone.s:22 Backtrace stopped: frame did not save the PC Thread 2 (LWP 21 "liquidsoap"): #0 __cp_end () at src/thread/x86_64/syscall_cp.s:29 #1 0x00007ae33c3e94fc in __syscall_cp_c (nr=23, u=, v=, w=, x=, y=, z=0) at src/thread/pthread_cancel.c:33 #2 0x00007ae33c3db4c2 in select (n=n@entry=0, rfds=rfds@entry=0x0, wfds=wfds@entry=0x0, efds=efds@entry=0x0, tv=tv@entry=0x7ae32a3f5a50) at src/select/select.c:39 #3 0x0000653409158a3c in st_msleep (msec=50) at /home/abuild/.opam/ocaml-base-compiler.5.2.0/.opam-switch/build/ocaml-base-compiler.5.2.0/otherlibs/systhreads/st_posix.h:25 #4 caml_thread_tick (arg=) at /home/abuild/.opam/ocaml-base-compiler.5.2.0/.opam-switch/build/ocaml-base-compiler.5.2.0/otherlibs/systhreads/st_pthreads.h:305 #5 0x00007ae33c3ea22e in start (p=0x7ae32a3f5ab8) at src/thread/pthread_create.c:207 #6 0x00007ae33c3ec82f in __clone () at src/thread/x86_64/clone.s:22 Backtrace stopped: frame did not save the PC Thread 1 (LWP 18 "liquidsoap"): #0 __cp_end () at src/thread/x86_64/syscall_cp.s:29 #1 0x00007ae33c3e94fc in __syscall_cp_c (nr=7, u=, v=, w=, x=, y=, z=0) at src/thread/pthread_cancel.c:33 #2 0x00007ae33c3db3db in poll (fds=fds@entry=0x7ae32af8ea50, n=n@entry=1, timeout=timeout@entry=-1) at src/select/poll.c:9 #3 0x0000653409157d75 in poll (__s=-1, __n=1, __f=0x7ae32af8ea50) at /usr/include/fortify/poll.h:40 #4 caml_poll (_read=, _write=, _err=, _timeout=) at duppy_stubs.c:95 #5 #6 0x000065340904be32 in camlDuppy.poll_596 () at src/duppy.ml:39 #7 0x0000653408cae985 in camlTutils.wait_for_done_1172 () at src/core/tools/tutils.ml:168 #8 0x0000653408cae880 in camlTutils.wait_done_1170 () at src/core/tools/tutils.ml:171 #9 0x0000653408cb03c7 in camlTutils.main_1581 () at src/core/tools/tutils.ml:362 #10 0x00006534090c3f80 in camlStdlib__List.iter_366 () at list.ml:112 #11 0x0000653408c97ee6 in camlLifecycle.action_457 () at src/core/tools/lifecycle.ml:64 #12 0x00006534090c3f80 in camlStdlib__List.iter_366 () at list.ml:112 #13 0x00006534090c3f80 in camlStdlib__List.iter_366 () at list.ml:112 #14 0x00006534090c3f80 in camlStdlib__List.iter_366 () at list.ml:112 #15 0x0000653408c50666 in camlDune__exe__Liquidsoap.entry () at src/runtime/runner.default.ml:25 #16 0x0000653408c49597 in caml_program () #17 #18 0x000065340919a78d in caml_startup_common (pooling=, argv=0x7fff36eec848) at runtime/startup_nat.c:132 #19 caml_startup_common (argv=0x7fff36eec848, pooling=) at runtime/startup_nat.c:88 #20 0x000065340919a7fb in caml_startup_exn (argv=) at runtime/startup_nat.c:139 #21 caml_startup (argv=) at runtime/startup_nat.c:144 #22 caml_main (argv=) at runtime/startup_nat.c:151 #23 0x0000653408c46e0c in main (argc=, argv=) at runtime/main.c:37 ```

To Reproduce

  1. docker run -it --rm ocaml/opam:alpine-3.19-ocaml-5.2 bash
  2. sudo apk add curl-dev pcre-dev linux-headers lame-dev
  3. opam install liquidsoap lame
  4. main.liq
    output.file(%mp3, {"/home/opam/main.mp3"}, sine())
  5. liquidsoap main.liq

Expected behavior No crash

Version details

Install method opam

Common issues N/A

toots commented 1 month ago

Thanks for this report. Do you know the OCaml version used for this build?

toots commented 1 month ago

Ha sorry 5.2. Ok. I'll keep this in mind for when we start recommending switching to OCaml 5.x