Skip to content

fix: EXT-X-DEFINE variable names colliding with Object.prototype - #8190

Open
istiakrahman15 wants to merge 3 commits into
video-dev:masterfrom
istiakrahman15:fix-ext-x-define-prototype
Open

istiakrahman15 wants to merge 3 commits into
video-dev:masterfrom
istiakrahman15:fix-ext-x-define-prototype

Conversation

@istiakrahman15

Copy link
Copy Markdown

Why is this Pull Request needed?

src/utils/variable-substitution.ts stored EXT-X-DEFINE variables in a plain {} object and tested names with the in operator, so names that exist on Object.prototype leaked through:

  • Defining NAME="constructor" once falsely reported a duplicate variable, because "constructor" in {} is true via the prototype, and the native Object() source text could end up substituted into a URI.
  • Referencing an undefined {$toString} produced no parsing error — native Object.prototype.toString source was substituted instead.

Per RFC 8216bis, constructor is a legal Variable Name, and an undefined variable reference must be a parsing error.

This PR will...

Change only the two places where the variable list is created, in src/utils/variable-substitution.ts (lines 55 and 100, in addVariableDefinition and importVariableDefinition):

parsed.variableList = variableList = Object.create(null);

With a null-prototype map, in returns false for prototype names and bracket access returns undefined for undefined names, so the existing error branches fire correctly.

It also adds regression tests in tests/unit/loader/m3u8-parser.ts, following the existing #EXT-X-DEFINE tests:

  • defining a variable named constructor once — no duplicate error, and {$constructor}/segment.ts resolves to https://cdn1.example/segment.ts
  • referencing an undefined {$toString} — a parsing error: Missing preceding EXT-X-DEFINE tag for Variable Reference: "toString"

Resolves issues:

Fixes #8187

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EXT-X-DEFINE: the Variable Names constructor and toString give a false duplicate error, and an undefined reference to toString gives no parsing error

1 participant