Skip to content

Commit

Permalink
Fix Uint8Array believed to be an ArrayBuffer when blacklisting based …
Browse files Browse the repository at this point in the history
…on key-id

Since at least the v3.21.1 release, we had an issue that appeared when
blacklisting Representation based on the keyID (e.g. when a
`keystatuseschange` event indicates us that we are "output-restricted
and when fallbacking is enabled through the related `keySystems`
options).

This issue prevented from fallbacking, it just threw an Error message
along the lines of:
`TypeError: DataView: expected ArrayBuffer, got Uint8Array`

The root cause was linked to typing issues (we consequently cleverly
redirect all wrong-doing to typescript, not our fault at all here :p:
microsoft/TypeScript#42534) where an
Uint8Array was considered to be a valid ArrayBuffer.

At some point, a `new
DataView(whatIThoughtToBeAnArrayBufferWhichIsInRealityAUint8Array)` was
done, leading to the aforementioned error.

The fix here is to now consider the type to be an Uint8Array and to do
Uint8Array things instead (i.e. no DataView anymore).
  • Loading branch information
peaBerberian committed Jan 28, 2021
1 parent 89233a7 commit db599e9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/core/eme/check_key_statuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export default function checkKeyStatuses(
session : MediaKeySession | ICustomMediaKeySession,
options: IKeyStatusesCheckingOptions,
keySystem: string
) : [IEMEWarningEvent[], ArrayBuffer[]] {
) : [IEMEWarningEvent[], Uint8Array[]] {
const warnings : IEMEWarningEvent[] = [];
const blacklistedKeyIDs : ArrayBuffer[] = [];
const blacklistedKeyIDs : Uint8Array[] = [];
const { fallbackOn = {}, throwOnLicenseExpiration } = options;

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
Expand Down
2 changes: 1 addition & 1 deletion src/core/eme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface ISessionUpdatedEvent {
// blacklisted.
// Emit the corresponding keyIDs as payload.
export interface IBlacklistKeysEvent { type : "blacklist-keys";
value: ArrayBuffer[]; }
value: Uint8Array[]; }

/**
* Event Emitted when specific "protection data" cannot be deciphered and is thus
Expand Down
5 changes: 2 additions & 3 deletions src/manifest/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ICustomError } from "../errors";
import { IParsedManifest } from "../parsers/manifest";
import areArraysOfNumbersEqual from "../utils/are_arrays_of_numbers_equal";
import arrayFind from "../utils/array_find";
import { isABEqualBytes } from "../utils/byte_parsing";
import EventEmitter from "../utils/event_emitter";
import idGenerator from "../utils/id_generator";
import warnOnce from "../utils/warn_once";
Expand Down Expand Up @@ -472,7 +471,7 @@ export default class Manifest extends EventEmitter<IManifestEvents> {
* performed.
* @param {Array.<ArrayBuffer>} keyIDs
*/
public addUndecipherableKIDs(keyIDs : ArrayBuffer[]) : void {
public addUndecipherableKIDs(keyIDs : Uint8Array[]) : void {
const updates = updateDeciperability(this, (representation) => {
if (representation.decipherable === false ||
representation.contentProtections === undefined)
Expand All @@ -483,7 +482,7 @@ export default class Manifest extends EventEmitter<IManifestEvents> {
for (let i = 0; i < contentKIDs.length; i++) {
const elt = contentKIDs[i];
for (let j = 0; j < keyIDs.length; j++) {
if (isABEqualBytes(keyIDs[j], elt.keyId)) {
if (areArraysOfNumbersEqual(keyIDs[j], elt.keyId)) {
return false;
}
}
Expand Down

0 comments on commit db599e9

Please sign in to comment.