Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #30493 from jimporter/music-invalid-files-2.2
Browse files Browse the repository at this point in the history
[Bug 1171202] Music app's scanning process can stall from invalid files
  • Loading branch information
rvandermeulen committed Jun 11, 2015
2 parents 1a4a3fd + 9798bf6 commit 90ac433
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 31 deletions.
1 change: 0 additions & 1 deletion apps/music/js/metadata/flac.js
Expand Up @@ -58,7 +58,6 @@ var FLACMetadata = (function() {
metadata.picture.end += block.view.viewOffset;
});
has_picture = true;

}

return (!has_vorbis_comment || !has_picture);
Expand Down
14 changes: 8 additions & 6 deletions apps/music/js/metadata/id3v2.js
Expand Up @@ -44,8 +44,12 @@ var ID3v2Metadata = (function() {
reject(err);
return;
}
parseFrames(header, moreview, metadata);
resolve(metadata);
try {
parseFrames(header, moreview, metadata);
resolve(metadata);
} catch(e) {
reject(e);
}
});
});
}
Expand Down Expand Up @@ -89,7 +93,7 @@ var ID3v2Metadata = (function() {
* @param {Object} header The header object for this ID3 tag.
* @param {BlobView} blobview The audio file to parse.
* @param {Metadata} metadata The (partially filled-in) metadata object.
* @return {Promise} A Promise returning the parsed metadata object.
* @return {Object} The metadata extracted from the ID3 tag.
*/
function parseFrames(header, blobview, metadata) {
// In id3v2.3, the "unsynchronized" flag in the tag header applies to
Expand All @@ -107,8 +111,7 @@ var ID3v2Metadata = (function() {
// In id3v2.4, the size includes itself, i.e. the rest of the header
// is |extended_header_size - 4|.
extended_header_size = blobview.readID3Uint28BE() - 4;
}
else { // id3version === 3
} else { // id3version === 3
// In id3v2.3, the size *excludes* itself, i.e. the rest of the header
// is |extended_header_size|.
extended_header_size = blobview.readUnsignedInt();
Expand All @@ -131,7 +134,6 @@ var ID3v2Metadata = (function() {
* @param {Object} header The header object for this ID3 tag.
* @param {BlobView} blobview The audio file being parsed.
* @param {Metadata} metadata The (partially filled-in) metadata object.
* @return {Promise} A Promise returning the parsed metadata object.
*/
function parseFrame(header, blobview, metadata) {
var frameid, framesize, frameflags, frame_unsynchronized = false;
Expand Down
49 changes: 25 additions & 24 deletions apps/music/js/metadata/ogg.js
Expand Up @@ -80,32 +80,33 @@ var OggMetadata = (function() {
return;
}

// Look for a comment header from a supported codec
var first_byte = fullpage.readByte();
var valid = false;
switch (first_byte) {
case 3:
valid = fullpage.readASCIIText(6) === 'vorbis';
metadata.tag_format = 'vorbis';
break;
case 79:
valid = fullpage.readASCIIText(7) === 'pusTags';
metadata.tag_format = 'opus';
break;
}
if (!valid) {
reject('malformed ogg comment packet');
return;
}
try {
// Look for a comment header from a supported codec
var first_byte = fullpage.readByte();
var valid = false;
switch (first_byte) {
case 3:
valid = fullpage.readASCIIText(6) === 'vorbis';
metadata.tag_format = 'vorbis';
break;
case 79:
valid = fullpage.readASCIIText(7) === 'pusTags';
metadata.tag_format = 'opus';
break;
}
if (!valid) {
reject('malformed ogg comment packet');
return;
}

readAllComments(fullpage, metadata);
readAllComments(fullpage, metadata);

LazyLoader.load('js/metadata/vorbis_picture.js', function() {
VorbisPictureComment.parsePictureComment(metadata).
then(function(metadata) {
resolve(metadata);
});
});
LazyLoader.load('js/metadata/vorbis_picture.js', function() {
VorbisPictureComment.parsePictureComment(metadata).then(resolve);
});
} catch(e) {
reject(e);
}
});
});
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions apps/music/test/unit/metadata/id3v2_test.js
Expand Up @@ -2,6 +2,7 @@
'use strict';

require('/test/unit/metadata/utils.js');
require('/js/metadata/id3v1.js');
require('/js/metadata/id3v2.js');

suite('id3v2 tags', function() {
Expand Down Expand Up @@ -236,4 +237,29 @@ suite('id3v2 tags', function() {
});

});

suite('invalid files', function() {

[2, 3, 4].forEach(function(version) {
suite('invalid id3v2.' + version, function() {

test('invalid frame size', function(done) {
var filename = '/test-data/id3v2.' + version +
'-invalid-frame-size.mp3';
parseMetadata(filename).catch(function(e) {
done();
});
});

test('invalid skipped frame', function(done) {
var filename = '/test-data/id3v2.' + version +
'-invalid-skipped-frame-size.mp3';
parseMetadata(filename).catch(function() {
done();
});
});
});
});

});
});

0 comments on commit 90ac433

Please sign in to comment.