From f6fcaadc8a33f7701b2a0c7b5abe6b8b274f62f0 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Sat, 12 Jun 2021 11:25:57 +0100 Subject: [PATCH] fix: catch errors in demuxers --- src/core/WebmBase.js | 13 ++++++++++--- src/opus/OggDemuxer.js | 13 +++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/core/WebmBase.js b/src/core/WebmBase.js index 453a4be..6e2bcf4 100644 --- a/src/core/WebmBase.js +++ b/src/core/WebmBase.js @@ -38,11 +38,17 @@ class WebmBaseDemuxer extends Transform { this._skipUntil = null; } else if (this._skipUntil) { this._count += chunk.length; - return done(); + done(); + return; } let result; while (result !== TOO_SHORT) { - result = this._readTag(chunk, offset); + try { + result = this._readTag(chunk, offset); + } catch (error) { + this.emit('error', error); + return; + } if (result === TOO_SHORT) break; if (result._skipUntil) { this._skipUntil = result._skipUntil; @@ -53,7 +59,8 @@ class WebmBaseDemuxer extends Transform { } this._count += offset; this._remainder = chunk.slice(offset); - return done(); + done(); + return; } /** diff --git a/src/opus/OggDemuxer.js b/src/opus/OggDemuxer.js index fdb1bc0..b0e8d09 100644 --- a/src/opus/OggDemuxer.js +++ b/src/opus/OggDemuxer.js @@ -32,10 +32,15 @@ class OggDemuxer extends Transform { this._remainder = null; } - while (chunk) { - const result = this._readPage(chunk); - if (result) chunk = result; - else break; + try { + while (chunk) { + const result = this._readPage(chunk); + if (result) chunk = result; + else break; + } + } catch (error) { + this.emit('error', error); + return; } this._remainder = chunk; done();