Opened 5 years ago

Closed 4 years ago

#2911 closed defect (fixed)

Handle initial chunk size packet of RTMP connections

Reported by: skyride Owned by:
Priority: important Component: avformat
Version: git-master Keywords: rtmp crash SISEGV
Cc: arkanis Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Version of FFMpeg:

skyride@ns308725:~/ffmpeg_sources/ffmpeg$ ffmpeg --version
ffmpeg version git-2013-08-28-129f506 Copyright (c) 2000-2013 the FFmpeg developers

built on Aug 28 2013 17:22:50 with gcc 4.7 (Debian 4.7.2-5)
configuration: --prefix=/home/skyride/ffmpeg_build --extra-cflags=-I/home/skyride/ffmpeg_build/include --extra-ldflags=-L/home/skyride/ffmpeg_build/lib --bindir=/home/skyride/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
libavutil 52. 42.100 / 52. 42.100
libavcodec 55. 29.100 / 55. 29.100
libavformat 55. 14.102 / 55. 14.102
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 82.102 / 3. 82.102
libswscale 2. 5.100 / 2. 5.100
libswresample 0. 17.103 / 0. 17.103
libpostproc 52. 3.100 / 52. 3.100

Summary of the bug:

A segmentation fault occurs when trying to open FFmpeg in listen mode for an RTMP stream, and initiating a connection.

How to reproduce:

ffmpeg -rtmp_listen 1 -re -i rtmp://skyride.org/app/asd -vcodec copy -acodec copy rtmp://live-fra.twitch.tv/app/MY_STREAM_KEY

The program then runs, and when I attempt to open a connection I receive the following message: "[rtmp @ 0x1b70ea0] Unable to read command string
Segmentation fault"

Attachments (3)

ffmpeg-20140412-203123.log (1.8 KB) - added by arkanis 4 years ago.
Verbose ffmpeg output
gdb-20140412.log (13.3 KB) - added by arkanis 4 years ago.
gdb output
0001-avformat-rtmpproto-Added-handling-of-an-initial-RTMP.patch (1.3 KB) - added by arkanis 4 years ago.
Patch to handle an initial chunk size packet

Download all attachments as: .zip

Change History (13)

comment:1 follow-up: Changed 5 years ago by skyride

Also to confirm, this occurs regardless of the output stream.

comment:2 in reply to: ↑ 1 Changed 5 years ago by cehoyos

Replying to skyride:

Also to confirm, this occurs regardless of the output stream.

If network output is not needed, please provide a command line using file or pipe protocol that allows to reproduce the problem.

comment:3 Changed 5 years ago by richardpl

I get error when using null output.

comment:4 Changed 5 years ago by cehoyos

Please add backtrace etc. for crashes as explained on http://ffmpeg.org/bugreports.html

comment:5 Changed 5 years ago by cehoyos

  • Resolution set to needs_more_info
  • Status changed from new to closed

Please reopen this ticket if you can add the missing information.

comment:6 Changed 4 years ago by arkanis

I also stumbled across the bug described by skyride. I think I found the cause and patched it (see below).

The bug occurred while I was trying to convert an RTMP stream to an HTTP stream. The RTMP stream is created with Open Broadcaster Software (https://obsproject.com/). The bug does not occur when ffmpeg is used as RTMP client!

Minimal setup to reproduce the bug:

  • Run ffmpeg as RTMP server: ./ffmpeg -listen 1 -i rtmp://192.168.17.2/test/app -c copy -y test.mp4
  • Open OBS and Stream data to the ffmpeg RTMP server
    • Set Options -> Broadcast Options -> Streaming-Platform to "Custom"
    • Set server to "rtmp://192.168.17.2/test/app"
    • Start streaming

Of course you should use your own IP. The used OBS version is v0.613b 32bit (Windows only). I tested ffmpeg v2.2.1 (on Windows and Linux) and the current master branch (e89f3d0ed21259a714a8bd5d05d95af5b1e0f73f on Linux). ffmpeg was compiled without librtmp so the native RTMP implementation is probably the error source.

I'll attach detailed ffmpeg and gdb output of these test cases.

Bug cause and how to fix it:

The error message "Unable to read command string" lead me to the read_connect() function in libavformat/rtmpproto.c. I think the code expects the first packet to be an invocation (type RTMP_PT_INVOKE) but OBS first sends an RTMP_PT_CHUNK_SIZE packet to increase the chunk size from 128 bytes to 4096 bytes.

The attached patch adds code to check for an initial chunk size packet and sets the RTMPContexts chunk size accordingly. I tried to replicate the coding style as much as possible.

I'm also not sure if I should post the bug on the development mailing list. I hope it's ok here since the ticket already exists.

Changed 4 years ago by arkanis

Verbose ffmpeg output

Changed 4 years ago by arkanis

gdb output

Changed 4 years ago by arkanis

Patch to handle an initial chunk size packet

comment:7 Changed 4 years ago by arkanis

  • Resolution needs_more_info deleted
  • Status changed from closed to reopened
  • Summary changed from Seg Fault to Handle initial chunk size packet of RTMP connections

comment:8 Changed 4 years ago by cehoyos

  • Cc arkanis added
  • Component changed from undetermined to avformat
  • Keywords rtmp crash SISEGV added
  • Priority changed from normal to important
  • Version changed from unspecified to git-master

Patches get more attention and can be reviewed on the ffmpeg-devel mailing list, please send the patch there.

comment:9 follow-up: Changed 4 years ago by arkanis

The patch has been accepted into the 2.2. and master branches, see http://ffmpeg.org/pipermail/ffmpeg-devel/2014-April/156655.html.

This should solve the bug. Can the ticket be closed?

comment:10 in reply to: ↑ 9 Changed 4 years ago by cehoyos

  • Resolution set to fixed
  • Status changed from reopened to closed

Replying to arkanis:

The patch has been accepted into the 2.2. and master branches, see http://ffmpeg.org/pipermail/ffmpeg-devel/2014-April/156655.html.

This should solve the bug. Can the ticket be closed?

Thank you for working on this issue!

Note: See TracTickets for help on using tickets.