diff --git a/src/format_speex.c b/src/format_speex.c index e7f6701c1c2d60a86cbd3ec3146a54f43373b791..ed3dd82ad3021c7f665b0783c03c8552e76dbd81 100644 --- a/src/format_speex.c +++ b/src/format_speex.c @@ -73,6 +73,19 @@ ogg_codec_t *initial_speex_page (format_plugin_t *plugin, ogg_page *page) ogg_stream_packetout (&codec->os, &packet); + /* Check for te first packet to be at least of the minimal size for a Speex header. + * The header size is 80 bytes as per specs. You can find the specs here: + * https://speex.org/docs/manual/speex-manual/node8.html#SECTION00830000000000000000 + * + * speex_packet_to_header() will also check the header size for us. However + * that function generates noise on stderr in case the header is too short. + * This is dangerous as we may have closed stderr already and the handle may be use + * again for something else. + */ + if (packet.bytes < 80) { + return NULL; + } + ICECAST_LOG_DEBUG("checking for speex codec"); header = speex_packet_to_header ((char*)packet.packet, packet.bytes); if (header == NULL)