Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent RangeError exception when parsing incomplete PES #2463

Merged
merged 1 commit into from Dec 6, 2019

Conversation

robwalch
Copy link
Collaborator

@robwalch robwalch commented Dec 6, 2019

This PR will...

Prevent RangeError exception when parsing incomplete PES.

Why is this Pull Request needed?

Remove exceptions in the critical path.

Are there any points in the code the reviewer needs to double check?

I'm not sure if the issue is that the PES are incomplete, empty or simply mishandled further up in the TS demuxer. Merging #2109 would avoid the exception with the test stream in #2415 altogether. That fix is scheduled for the next patch so that we can test the full scope of those changes.

Resolves issues:

Fixes #2415
Relates to #2109

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@robwalch robwalch added this to the 0.13.0 milestone Dec 6, 2019
@@ -499,6 +499,9 @@ class TSDemuxer {
// 9 bytes : 6 bytes for PES header + 3 bytes for PES extension
payloadStartOffset = pesHdrLen + 9;

if (stream.size <= payloadStartOffset) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine by me, however could we simply modify the pre-existing safety checks that exist on lines 439-440?
What you have here now may cover other cases that I'm not considering, but I thought I would ask 😄

The safety check I'm referencing:

    // safety check
    if (!stream || stream.size === 0) {
      return null;
    }	

Copy link
Collaborator Author

@robwalch robwalch Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelcunningham19 I'd like to, but I'm not certain what the length of payloadStartOffset will be at this point.

payloadStartOffset = pesHdrLen + 9;

I think we could change the safety check to || stream.size < 10) { but that still wont cover cases where pesHdrLen ends up topping the input size.

@robwalch robwalch merged commit 63efbc0 into master Dec 6, 2019
@robwalch robwalch deleted the bugfix/parse-pes-error branch December 6, 2019 20:08
@robwalch robwalch added this to Done in 0.13.0 Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
0.13.0
  
Done
Development

Successfully merging this pull request may close these issues.

_parsePES error leading to a stall.
3 participants