karlheyes / icecast-kh

KH branch of icecast
GNU General Public License v2.0
300 stars 107 forks source link

Memory corruption in FLV wrapping if there is not enough allocated space for metadata #347

Open lalinsky opened 3 years ago

lalinsky commented 3 years ago

We had a crash when station was using long name. This is the situation:

In the log file, it looks like this:

[2021-02-17  08:37:58] DBUG flv/flv_meta_increase 4 array elements
[2021-02-17  08:37:58] DBUG flv/flv_meta_increase 4 array elements
[2021-02-17  08:37:58] DBUG flv/flv_meta_increase 4 array elements
[2021-02-17  08:37:58] DBUG flv/flv_meta_increase 4 array elements
[2021-02-17  08:37:58] DBUG flv/flv_meta_increase 4 array elements
[2021-02-17  08:37:58] DBUG flv/flv_meta_increase 4 array elements
[2021-02-17  08:37:58] DBUG flv/flv_meta_increase 4 array elements

Then there is some other activity and then it crashes, because of the corrupted memory.

The fix does two things:

With this patch (and assuming the stream name is really super long, but below the 4000 - 5 bytes), the error log looks like this:

[2021-02-17  08:48:41] WARN flv/flv_meta_append_number not enough space for audiodatarate
[2021-02-17  08:48:41] WARN flv/flv_meta_append_number not enough space for audiosamplerate
[2021-02-17  08:48:41] WARN flv/flv_meta_append_bool not enough space for canSeekToEnd
[2021-02-17  08:48:41] WARN flv/flv_meta_append_bool not enough space for hasMetadata
[2021-02-17  08:48:41] WARN flv/flv_meta_append_bool not enough space for hasVideo
[2021-02-17  08:48:41] WARN flv/flv_meta_append_bool not enough space for hasAudio