diff --git a/README.md b/README.md index 71ded5a630..527c0e86fc 100755 --- a/README.md +++ b/README.md @@ -344,7 +344,8 @@ Remark: ### SRS 2.0 history -* v2.0, 2015-05-30, fix [#420](https://github.com/simple-rtmp-server/srs/issues/420) remove ts for hls ram mode. +* v2.0, 2015-06-06, fix [#421](https://github.com/simple-rtmp-server/srs/issues/421) drop video for unkown RTMP header. +* v2.0, 2015-06-05, fix [#420](https://github.com/simple-rtmp-server/srs/issues/420) remove ts for hls ram mode. * v2.0, 2015-05-30, fix [#209](https://github.com/simple-rtmp-server/srs/issues/209) cleanup hls when stop and timeout. 2.0.173. * v2.0, 2015-05-29, fix [#409](https://github.com/simple-rtmp-server/srs/issues/409) support pure video hls. 2.0.172. * v2.0, 2015-05-28, support [srs-dolphin][srs-dolphin], the multiple-process SRS. diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 6c853533ed..042913b515 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1633,6 +1633,18 @@ int SrsSource::on_video(SrsCommonMessage* shared_video) { int ret = ERROR_SUCCESS; + // drop any unknown header video. + // @see https://github.com/simple-rtmp-server/srs/issues/421 + if (!SrsFlvCodec::video_is_acceptable(shared_video->payload, shared_video->size)) { + char b0 = 0x00; + if (shared_video->size > 0) { + b0 = shared_video->payload[0]; + } + + srs_warn("drop unknown header video, size=%d, bytes[0]=%#x", shared_video->size, b0); + return ret; + } + // convert shared_video to msg, user should not use shared_video again. // the payload is transfer to msg, and set to NULL in shared_video. SrsSharedPtrMessage msg; diff --git a/trunk/src/kernel/srs_kernel_codec.cpp b/trunk/src/kernel/srs_kernel_codec.cpp index 21981506c0..0436c25fa2 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -266,6 +266,28 @@ bool SrsFlvCodec::audio_is_aac(char* data, int size) return sound_format == SrsCodecAudioAAC; } +bool SrsFlvCodec::video_is_acceptable(char* data, int size) +{ + // 1bytes required. + if (size < 1) { + return false; + } + + char frame_type = data[0]; + char codec_id = frame_type & 0x0f; + frame_type = (frame_type >> 4) & 0x0f; + + if (frame_type < 1 || frame_type > 5) { + return false; + } + + if (codec_id < 2 || codec_id > 7) { + return false; + } + + return true; +} + string srs_codec_avc_nalu2str(SrsAvcNaluType nalu_type) { switch (nalu_type) { diff --git a/trunk/src/kernel/srs_kernel_codec.hpp b/trunk/src/kernel/srs_kernel_codec.hpp index 702106101a..238feac763 100644 --- a/trunk/src/kernel/srs_kernel_codec.hpp +++ b/trunk/src/kernel/srs_kernel_codec.hpp @@ -222,6 +222,12 @@ class SrsFlvCodec * check codec aac. */ static bool audio_is_aac(char* data, int size); + /** + * check the video RTMP/flv header info, + * @return true if video RTMP/flv header is ok. + * @remark all type of audio is possible, no need to check audio. + */ + static bool video_is_acceptable(char* data, int size); }; /**