Skip to content

Commit b11ddc7

Browse files
committed
Fix #834, crash for TS context corrupt. 2.0.235
1 parent 7d1a91c commit b11ddc7

File tree

7 files changed

+31
-2
lines changed

7 files changed

+31
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ Remark:
336336

337337
## History
338338

339+
* v2.0, 2017-04-09, Fix [#834][bug #834], crash for TS context corrupt. 2.0.235
339340
* <strong>v2.0, 2017-03-03, [2.0 release0(2.0.234)][r2.0r0] released. 86373 lines.</strong>
340341
* v2.0, 2017-02-25, for [#730][bug #730], remove the test code. 2.0.234
341342
* v2.0, 2017-02-09, fix [#503][bug #503] disable utilities when reload a source. 2.0.233
@@ -1279,6 +1280,7 @@ Winlin
12791280
[bug #750]: https://github.com/ossrs/srs/issues/750
12801281
[bug #752]: https://github.com/ossrs/srs/issues/752
12811282
[bug #503]: https://github.com/ossrs/srs/issues/503
1283+
[bug #834]: https://github.com/ossrs/srs/issues/834
12821284
[bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
12831285

12841286
[exo #828]: https://github.com/google/ExoPlayer/pull/828

trunk/auto/build_ffmpeg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ else
4242
echo "build fdk-aac-0.1.3"
4343
cd $ff_current_dir &&
4444
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
4646
ret=$?; if [[ 0 -ne ${ret} ]]; then echo "build fdk-aac-0.1.3 failed"; exit 1; fi
4747
fi
4848

trunk/src/app/srs_app_rtmp_conn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ int SrsRtmpConn::stream_service_cycle()
481481
return ret;
482482
}
483483
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+
}
484492

485493
// client is identified, set the timeout to service timeout.
486494
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_RECV_TIMEOUT_US);

trunk/src/core/srs_core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3131
// current release version
3232
#define VERSION_MAJOR 2
3333
#define VERSION_MINOR 0
34-
#define VERSION_REVISION 234
34+
#define VERSION_REVISION 235
3535

3636
// generated by configure, only macros.
3737
#include <srs_auto_headers.hpp>

trunk/src/kernel/srs_kernel_error.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
152152
#define ERROR_RTSP_AUDIO_CONFIG 2047
153153
#define ERROR_RTMP_STREAM_NOT_FOUND 2048
154154
#define ERROR_RTMP_CLIENT_NOT_FOUND 2049
155+
#define ERROR_RTMP_STREAM_NAME_EMPTY 2050
155156
//
156157
// system control message,
157158
// not an error, but special control logic.
@@ -230,6 +231,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
230231
#define ERROR_RESPONSE_CODE 3064
231232
#define ERROR_RESPONSE_DATA 3065
232233
#define ERROR_REQUEST_DATA 3066
234+
#define ERROR_TS_CONTEXT_NOT_READY 3067
233235

234236
///////////////////////////////////////////////////////
235237
// HTTP/StreamCaster protocol error.

trunk/src/kernel/srs_kernel_ts.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ ISrsTsHandler::~ISrsTsHandler()
199199

200200
SrsTsContext::SrsTsContext()
201201
{
202+
ready = false;
202203
pure_audio = false;
203204
vcodec = SrsCodecVideoReserved;
204205
acodec = SrsCodecAudioReserved1;
@@ -234,6 +235,7 @@ void SrsTsContext::on_pmt_parsed()
234235

235236
void SrsTsContext::reset()
236237
{
238+
ready = false;
237239
vcodec = SrsCodecVideoReserved;
238240
acodec = SrsCodecAudioReserved1;
239241
}
@@ -432,13 +434,23 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea
432434
return ret;
433435
}
434436
}
437+
438+
// When PAT and PMT are writen, the context is ready now.
439+
ready = true;
435440

436441
return ret;
437442
}
438443

439444
int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t pid, SrsTsStream sid, bool pure_audio)
440445
{
441446
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+
}
442454

443455
if (msg->payload->length() == 0) {
444456
return ret;

trunk/src/kernel/srs_kernel_ts.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ class ISrsTsHandler
346346
*/
347347
class SrsTsContext
348348
{
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;
349354
// codec
350355
private:
351356
std::map<int, SrsTsChannel*> pids;

0 commit comments

Comments
 (0)