Skip to content

fix(m3u8-parser): parse DateRanges whose IDs match Object.prototype properties - #8201

Open
MFA-G wants to merge 1 commit into
video-dev:masterfrom
MFA-G:fix/daterange-object-prototype-ids
Open

MFA-G wants to merge 1 commit into
video-dev:masterfrom
MFA-G:fix/daterange-object-prototype-ids

Conversation

@MFA-G

@MFA-G MFA-G commented Nov 29, 2026

Copy link
Copy Markdown

Problem

An EXT-X-DATERANGE ID that is also a name on Object.prototype (toString, constructor, hasOwnProperty, __proto__) makes M3U8Parser.parseLevelPlaylist() throw:

TypeError: Cannot read properties of undefined (reading 'getTime')

LevelDetails.dateRanges is a plain object, so level.dateRanges[ID] resolves to an inherited member when no earlier Date Range with that ID exists. The DateRange constructor treats that member as the previous Date Range, copies its undefined start date, and mapDateRanges() later calls getTime() on it. RFC 8216bis §4.4.5.1 only says the ID is a quoted-string, so these are valid IDs.

Fix

Store dateRanges in null-prototype objects:

  • LevelDetails now creates Object.create(null).
  • mergeDateRanges() copies the old map into Object.create(null) as well, so a delta update cannot reintroduce the inherited lookup.

Only own keys are visible now, and Object.keys()/iteration behave as before. This mirrors the variableList fix in #8190.

Tests

Two new unit tests, both failing on master with the TypeError above and passing with the fix:

  • parses DATERANGE tags whose ID matches an Object.prototype property (tests/unit/loader/m3u8-parser.ts) covers toString, constructor, hasOwnProperty, __proto__ and checks startTime.
  • merges delta Playlist DateRanges whose IDs match Object.prototype properties (tests/unit/controller/level-helper.ts) covers a CAN-SKIP-DATERANGES update that keeps, matches and adds such IDs.

Validation on the branch:

npm run test:unit   # 1285 tests passed
npx tsc --noEmit    # clean
npm run build       # rollup + api-extractor clean
npx eslint <changed files> && npx prettier --check <changed files>  # clean

Fixes #8188.

A DateRange ID such as "toString" or "constructor" resolved to an inherited
Object.prototype member when the parser looked for a previous DateRange with
the same ID. The DateRange constructor then copied properties from a function,
leaving its start date undefined, and mapDateRanges threw on getTime().

Store dateRanges in null-prototype objects in LevelDetails and when merging
delta playlist DateRanges, so every ID is an own key regardless of its name.

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-DATERANGE with the ID toString or constructor makes parseLevelPlaylist throw a TypeError

1 participant