Skip to content

Commit

Permalink
added a catch for an out of range buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
isuttell authored and datagutt committed Apr 24, 2019
1 parent 4978533 commit aa39f95
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion node_rtmp_session.js
Expand Up @@ -5,6 +5,7 @@
//

const QueryString = require("querystring");
const buffer = require('buffer');
const AV = require("./node_core_av");
const { AUDIO_SOUND_RATE, AUDIO_CODEC_NAME, VIDEO_CODEC_NAME } = require("./node_core_av");

Expand Down Expand Up @@ -351,10 +352,18 @@ class NodeRtmpSession {
chunksOffset += chunkBasicHeader.length;
chunkMessageHeader.copy(chunks, chunksOffset);
chunksOffset += chunkMessageHeader.length;
if (useExtendedTimestamp) {

// See https://github.com/illuspas/Node-Media-Server/issues/123
const isOutofRange = (header.timestamp + chunksOffset) > buffer.constants.MAX_LENGTH;
if (isOutofRange) {
Logger.warn('header.timestamp is out of range of buffer -> header.timestamp = %s', header.timestamp + chunksOffset);
}

if (useExtendedTimestamp && !isOutofRange) {
chunks.writeUInt32BE(header.timestamp, chunksOffset);
chunksOffset += 4;
}

while (payloadSize > 0) {
if (payloadSize > chunkSize) {
payload.copy(chunks, chunksOffset, payloadOffset, payloadOffset + chunkSize);
Expand Down

0 comments on commit aa39f95

Please sign in to comment.