winlin

Fix #834, crash for TS context corrupt. 2.0.235

@@ -336,6 +336,7 @@ Remark: @@ -336,6 +336,7 @@ Remark:
336 336
337 ## History 337 ## History
338 338
  339 +* v2.0, 2017-04-09, Fix [#834][bug #834], crash for TS context corrupt. 2.0.235
339 * <strong>v2.0, 2017-03-03, [2.0 release0(2.0.234)][r2.0r0] released. 86373 lines.</strong> 340 * <strong>v2.0, 2017-03-03, [2.0 release0(2.0.234)][r2.0r0] released. 86373 lines.</strong>
340 * v2.0, 2017-02-25, for [#730][bug #730], remove the test code. 2.0.234 341 * v2.0, 2017-02-25, for [#730][bug #730], remove the test code. 2.0.234
341 * v2.0, 2017-02-09, fix [#503][bug #503] disable utilities when reload a source. 2.0.233 342 * v2.0, 2017-02-09, fix [#503][bug #503] disable utilities when reload a source. 2.0.233
@@ -1279,6 +1280,7 @@ Winlin @@ -1279,6 +1280,7 @@ Winlin
1279 [bug #750]: https://github.com/ossrs/srs/issues/750 1280 [bug #750]: https://github.com/ossrs/srs/issues/750
1280 [bug #752]: https://github.com/ossrs/srs/issues/752 1281 [bug #752]: https://github.com/ossrs/srs/issues/752
1281 [bug #503]: https://github.com/ossrs/srs/issues/503 1282 [bug #503]: https://github.com/ossrs/srs/issues/503
  1283 +[bug #834]: https://github.com/ossrs/srs/issues/834
1282 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx 1284 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
1283 1285
1284 [exo #828]: https://github.com/google/ExoPlayer/pull/828 1286 [exo #828]: https://github.com/google/ExoPlayer/pull/828
@@ -42,7 +42,7 @@ else @@ -42,7 +42,7 @@ else
42 echo "build fdk-aac-0.1.3" 42 echo "build fdk-aac-0.1.3"
43 cd $ff_current_dir && 43 cd $ff_current_dir &&
44 rm -rf fdk-aac-0.1.3 && unzip -q ${ff_src_dir}/fdk-aac-0.1.3.zip && 44 rm -rf fdk-aac-0.1.3 && unzip -q ${ff_src_dir}/fdk-aac-0.1.3.zip &&
45 - cd fdk-aac-0.1.3 && bash autogen.sh && ./configure --prefix=${ff_release_dir} --enable-static && make ${SRS_JOBS} && make install && 45 + cd fdk-aac-0.1.3 && bash autogen.sh && ./configure --prefix=${ff_release_dir} --enable-static && make ${SRS_JOBS} && make install
46 ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build fdk-aac-0.1.3 failed"; exit 1; fi 46 ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build fdk-aac-0.1.3 failed"; exit 1; fi
47 fi 47 fi
48 48
@@ -481,6 +481,14 @@ int SrsRtmpConn::stream_service_cycle() @@ -481,6 +481,14 @@ int SrsRtmpConn::stream_service_cycle()
481 return ret; 481 return ret;
482 } 482 }
483 srs_info("security check ok"); 483 srs_info("security check ok");
  484 +
  485 + // Never allow the empty stream name, for HLS may write to a file with empty name.
  486 + // @see https://github.com/ossrs/srs/issues/834
  487 + if (req->stream.empty()) {
  488 + ret = ERROR_RTMP_STREAM_NAME_EMPTY;
  489 + srs_error("RTMP: Empty stream name not allowed, ret=%d", ret);
  490 + return ret;
  491 + }
484 492
485 // client is identified, set the timeout to service timeout. 493 // client is identified, set the timeout to service timeout.
486 rtmp->set_recv_timeout(SRS_CONSTS_RTMP_RECV_TIMEOUT_US); 494 rtmp->set_recv_timeout(SRS_CONSTS_RTMP_RECV_TIMEOUT_US);
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 234 34 +#define VERSION_REVISION 235
35 35
36 // generated by configure, only macros. 36 // generated by configure, only macros.
37 #include <srs_auto_headers.hpp> 37 #include <srs_auto_headers.hpp>
@@ -152,6 +152,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -152,6 +152,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
152 #define ERROR_RTSP_AUDIO_CONFIG 2047 152 #define ERROR_RTSP_AUDIO_CONFIG 2047
153 #define ERROR_RTMP_STREAM_NOT_FOUND 2048 153 #define ERROR_RTMP_STREAM_NOT_FOUND 2048
154 #define ERROR_RTMP_CLIENT_NOT_FOUND 2049 154 #define ERROR_RTMP_CLIENT_NOT_FOUND 2049
  155 +#define ERROR_RTMP_STREAM_NAME_EMPTY 2050
155 // 156 //
156 // system control message, 157 // system control message,
157 // not an error, but special control logic. 158 // not an error, but special control logic.
@@ -230,6 +231,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -230,6 +231,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
230 #define ERROR_RESPONSE_CODE 3064 231 #define ERROR_RESPONSE_CODE 3064
231 #define ERROR_RESPONSE_DATA 3065 232 #define ERROR_RESPONSE_DATA 3065
232 #define ERROR_REQUEST_DATA 3066 233 #define ERROR_REQUEST_DATA 3066
  234 +#define ERROR_TS_CONTEXT_NOT_READY 3067
233 235
234 /////////////////////////////////////////////////////// 236 ///////////////////////////////////////////////////////
235 // HTTP/StreamCaster protocol error. 237 // HTTP/StreamCaster protocol error.
@@ -199,6 +199,7 @@ ISrsTsHandler::~ISrsTsHandler() @@ -199,6 +199,7 @@ ISrsTsHandler::~ISrsTsHandler()
199 199
200 SrsTsContext::SrsTsContext() 200 SrsTsContext::SrsTsContext()
201 { 201 {
  202 + ready = false;
202 pure_audio = false; 203 pure_audio = false;
203 vcodec = SrsCodecVideoReserved; 204 vcodec = SrsCodecVideoReserved;
204 acodec = SrsCodecAudioReserved1; 205 acodec = SrsCodecAudioReserved1;
@@ -234,6 +235,7 @@ void SrsTsContext::on_pmt_parsed() @@ -234,6 +235,7 @@ void SrsTsContext::on_pmt_parsed()
234 235
235 void SrsTsContext::reset() 236 void SrsTsContext::reset()
236 { 237 {
  238 + ready = false;
237 vcodec = SrsCodecVideoReserved; 239 vcodec = SrsCodecVideoReserved;
238 acodec = SrsCodecAudioReserved1; 240 acodec = SrsCodecAudioReserved1;
239 } 241 }
@@ -432,6 +434,9 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea @@ -432,6 +434,9 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea
432 return ret; 434 return ret;
433 } 435 }
434 } 436 }
  437 +
  438 + // When PAT and PMT are writen, the context is ready now.
  439 + ready = true;
435 440
436 return ret; 441 return ret;
437 } 442 }
@@ -439,6 +444,13 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea @@ -439,6 +444,13 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea
439 int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t pid, SrsTsStream sid, bool pure_audio) 444 int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t pid, SrsTsStream sid, bool pure_audio)
440 { 445 {
441 int ret = ERROR_SUCCESS; 446 int ret = ERROR_SUCCESS;
  447 +
  448 + // Sometimes, the context is not ready(PAT/PMT write failed), error in this situation.
  449 + if (!ready) {
  450 + ret = ERROR_TS_CONTEXT_NOT_READY;
  451 + srs_error("TS: context not ready, ret=%d", ret);
  452 + return ret;
  453 + }
442 454
443 if (msg->payload->length() == 0) { 455 if (msg->payload->length() == 0) {
444 return ret; 456 return ret;
@@ -346,6 +346,11 @@ public: @@ -346,6 +346,11 @@ public:
346 */ 346 */
347 class SrsTsContext 347 class SrsTsContext
348 { 348 {
  349 +private:
  350 + // Whether context is ready, failed if try to write data when not ready.
  351 + // When PAT and PMT writen, the context is ready.
  352 + // @see https://github.com/ossrs/srs/issues/834
  353 + bool ready;
349 // codec 354 // codec
350 private: 355 private:
351 std::map<int, SrsTsChannel*> pids; 356 std::map<int, SrsTsChannel*> pids;