Skip to content

Commit

Permalink
fix: Prevent exception when PlayReady CDM returns UTF-8 unwrapped mes…
Browse files Browse the repository at this point in the history
…sage
  • Loading branch information
vodlogic committed Apr 19, 2022
1 parent 2aad3e7 commit 4164dae
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/streaming/protection/drm/KeySystemPlayReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ function KeySystemPlayReady(config) {
xmlDoc;
const headers = {};
const parser = new DOMParser();

// If message format configured/defaulted to utf-16 AND number of bytes is odd, assume 'unwrapped' raw CDM message.
if (messageFormat === 'utf-16' && message.byteLength % 2 === 1) {
headers['Content-Type'] = 'text/xml; charset=utf-8';
return headers;
}

const dataview = (messageFormat === 'utf-16') ? new Uint16Array(message) : new Uint8Array(message);

msg = String.fromCharCode.apply(null, dataview);
Expand Down Expand Up @@ -89,6 +96,12 @@ function KeySystemPlayReady(config) {
function getLicenseRequestFromMessage(message) {
let licenseRequest = null;
const parser = new DOMParser();

// If message format configured/defaulted to utf-16 AND number of bytes is odd, assume 'unwrapped' raw CDM message.
if (messageFormat === 'utf-16' && message.byteLength % 2 === 1) {
return message;
}

const dataview = (messageFormat === 'utf-16') ? new Uint16Array(message) : new Uint8Array(message);

checkConfig();
Expand Down

0 comments on commit 4164dae

Please sign in to comment.