Skip to content

Commit

Permalink
Fix CTOC reading logic for reading child ids
Browse files Browse the repository at this point in the history
The readNullTerminatedString was being called with the wrong length argument.
Also fixed the tests because they were relying on ArrayFileReader not to throw on out of bounds exceptions.
  • Loading branch information
aadsm committed Aug 6, 2017
1 parent 8be25a2 commit 5d71696
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ID3v2FrameReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ frameReaderFunctions['CTOC'] = function readTableOfContentsFrame(
result.entryCount = data.getByteAt(offset);
offset++;
for (var i = 0; i < result.entryCount; i++) {
var childId = StringUtils.readNullTerminatedString(data.getBytesAt(offset, length));
var childId = StringUtils.readNullTerminatedString(data.getBytesAt(offset, length - (offset - originalOffset)));
result.childElementIds.push(childId.toString());
offset += childId.bytesReadCount;
}
Expand Down
27 changes: 24 additions & 3 deletions src/__tests__/ID3v2FrameReader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,15 @@ describe("ID3v2FrameReader", function() {
[0b00000011], // toplevel/ordered bit
[0x02], // entry count
bin("ID2"), [0x00], // child 1
bin("ID3"), [0x00] // child 2
bin("ID3"), [0x00], // child 2
bin("TIT1"), // child 1
[0x00, 0x00, 0x00, 0x02], // size
[0x00, 0x00], // flags
[0x00, 0x00], // text encoding + null terminated string
bin("TIT2"), // child 2
[0x00, 0x00, 0x00, 0x02], // size
[0x00, 0x00], // flags
[0x00, 0x00] // text encoding + null terminated string
);
var fileReader = new ArrayFileReader(fileData);
var data = frameReader(0, fileData.length, fileReader, null, {major: 3});
Expand All @@ -341,8 +349,21 @@ describe("ID3v2FrameReader", function() {
ordered: true,
entryCount: 2,
childElementIds: [ "ID2", "ID3" ],
subFrames: {} }
);
subFrames: {
TIT1: {
data: '',
description: 'Content group description',
id: 'TIT1',
size: 2
},
TIT2: {
data: '',
description: 'Title/songname/content description',
id: 'TIT2',
size: 2
}
}
});
});

it("should read CHAP tag", function() {
Expand Down

0 comments on commit 5d71696

Please sign in to comment.