Skip to content

Commit bc40027

Browse files
committed
Add workaround for faulty MP3ext padding
MP3ext V3.3.17 places a non-compliant padding string at the end of the ID3v2 header. To get around this problem the program stops reading frames as soon as the padding is detected to avoid overflow reading. Fixes #58
1 parent f2caee5 commit bc40027

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/ID3v2FrameReader.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ class ID3v2FrameReader {
227227
if (tags && tags.indexOf(frameId) === -1) {
228228
continue;
229229
}
230+
// Workaround: MP3ext V3.3.17 places a non-compliant padding string at
231+
// the end of the ID3v2 header. A string like "MP3ext V3.3.19(ansi)"
232+
// is added multiple times at the end of the ID3 tag. More information
233+
// about this issue can be found at
234+
// https://github.com/aadsm/jsmediatags/issues/58#issuecomment-313865336
235+
if (
236+
frameId === 'MP3e' || frameId === '\x00MP3' ||
237+
frameId === '\x00\x00MP' || frameId === ' MP3'
238+
) {
239+
break;
240+
}
230241

231242
var unsyncData;
232243
if (flags && flags.format.unsynchronisation) {

src/__tests__/ID3v2FrameReader-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,26 @@ describe("ID3v2FrameReader", function() {
370370
subFrames: {}
371371
});
372372
});
373+
374+
it("should ignore faulty MP3ext padding", function() {
375+
var artistName = bin("Lead Artist");
376+
var mp3extPadding = bin("MP3ext V3.3.19(ansi) MP3ext V3.3.19(ansi)");
377+
var fileData = [].concat(
378+
// Good tag
379+
bin("TPE1"),
380+
[0x00, 0x00, 0x00, 1 + artistName.length], // size
381+
[0x00, 0x00], // flags
382+
[0x00], // text encoding
383+
artistName, // content
384+
// MP3ext faulty padding
385+
mp3extPadding
386+
);
387+
var fileReader = new ArrayFileReader(fileData);
388+
var id3header = {major: 4};
389+
390+
var tags = ID3v2FrameReader.readFrames(
391+
0, fileData.length, fileReader, id3header
392+
);
393+
expect(tags.MP3e).not.toBeDefined();
394+
});
373395
});

0 commit comments

Comments
 (0)