mpris: Validate received data against the expected types from the spec

In the wild we have buggy clients (notably Chromium 77 and earlier) that
send metadata with the wrong types. Previously, this would throw an
exception and prevent the MPRIS information from showing up in the
message list.

This changes the code to check if any incoming metadata is of the type
it is expected to be, and logs a warning if not, then continues on with
a default value.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1362
This commit is contained in:
Philip Chimento 2019-10-28 17:06:40 -07:00 committed by Florian Müllner
parent 39e6fc9e9d
commit 975280fc50

View File

@ -95,6 +95,7 @@ var MprisPlayer = class MprisPlayer {
this._trackArtists = []; this._trackArtists = [];
this._trackTitle = ''; this._trackTitle = '';
this._trackCoverUrl = ''; this._trackCoverUrl = '';
this._busName = busName;
} }
get status() { get status() {
@ -177,9 +178,36 @@ var MprisPlayer = class MprisPlayer {
for (let prop in this._playerProxy.Metadata) for (let prop in this._playerProxy.Metadata)
metadata[prop] = this._playerProxy.Metadata[prop].deep_unpack(); metadata[prop] = this._playerProxy.Metadata[prop].deep_unpack();
this._trackArtists = metadata['xesam:artist'] || [_("Unknown artist")]; // Validate according to the spec; some clients send buggy metadata:
this._trackTitle = metadata['xesam:title'] || _("Unknown title"); // https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata
this._trackCoverUrl = metadata['mpris:artUrl'] || ''; this._trackArtists = metadata['xesam:artist'];
if (!Array.isArray(this._trackArtists) ||
!this._trackArtists.every(artist => typeof artist === 'string')) {
if (typeof this._trackArtists !== 'undefined')
log(`Received faulty track artist metadata from ${
this._busName}; expected an array of strings, got ${
this._trackArtists} (${typeof this._trackArtists})`);
this._trackArtists = [_("Unknown artist")];
}
this._trackTitle = metadata['xesam:title'];
if (typeof this._trackTitle !== 'string') {
if (typeof this._trackTitle !== 'undefined')
log(`Received faulty track title metadata from ${
this._busName}; expected a string, got ${
this._trackTitle} (${typeof this._trackTitle})`);
this._trackTitle = _("Unknown title");
}
this._trackCoverUrl = metadata['mpris:artUrl'];
if (typeof this._trackCoverUrl !== 'string') {
if (typeof this._trackCoverUrl !== 'undefined')
log(`Received faulty track cover art metadata from ${
this._busName}; expected a string, got ${
this._trackCoverUrl} (${typeof this._trackCoverUrl})`);
this._trackCoverUrl = '';
}
this.emit('changed'); this.emit('changed');
let visible = this._playerProxy.CanPlay; let visible = this._playerProxy.CanPlay;