e1e725cd by David LaPalomento

TXXX value fields are null-terminated in practice

Two tools used to inject TXXX frames terminate the value field with a null byte. Make sure that isn't included in the parsed representation.
1 parent 95aa0508
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
37 if (tag.data[i] === 0) { 37 if (tag.data[i] === 0) {
38 // parse the text fields 38 // parse the text fields
39 tag.description = parseUtf8(tag.data, 1, i); 39 tag.description = parseUtf8(tag.data, 1, i);
40 tag.value = parseUtf8(tag.data, i + 1, tag.data.length); 40 // do not include the null terminator in the tag value
41 tag.value = parseUtf8(tag.data, i + 1, tag.data.length - 1);
41 break; 42 break;
42 } 43 }
43 } 44 }
......
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
201 data: new Uint8Array(id3Tag(id3Frame('TXXX', 201 data: new Uint8Array(id3Tag(id3Frame('TXXX',
202 0x03, // utf-8 202 0x03, // utf-8
203 stringToCString('get done'), 203 stringToCString('get done'),
204 stringToInts('{ "key": "value" }')), 204 stringToCString('{ "key": "value" }')),
205 [0x00, 0x00])) 205 [0x00, 0x00]))
206 }); 206 });
207 207
...@@ -209,7 +209,7 @@ ...@@ -209,7 +209,7 @@
209 equal(events[0].frames.length, 1, 'parsed one frame'); 209 equal(events[0].frames.length, 1, 'parsed one frame');
210 equal(events[0].frames[0].id, 'TXXX', 'parsed the frame id'); 210 equal(events[0].frames[0].id, 'TXXX', 'parsed the frame id');
211 equal(events[0].frames[0].description, 'get done', 'parsed the description'); 211 equal(events[0].frames[0].description, 'get done', 'parsed the description');
212 equal(events[0].frames[0].value, '{ "key": "value" }', 'parsed the value'); 212 deepEqual(JSON.parse(events[0].frames[0].value), { key: 'value' }, 'parsed the value');
213 }); 213 });
214 214
215 test('parses WXXX frames', function() { 215 test('parses WXXX frames', function() {
...@@ -253,7 +253,7 @@ ...@@ -253,7 +253,7 @@
253 data: new Uint8Array(id3Tag(id3Frame('TXXX', 253 data: new Uint8Array(id3Tag(id3Frame('TXXX',
254 0x03, // utf-8 254 0x03, // utf-8
255 stringToCString(''), 255 stringToCString(''),
256 stringToInts(value)), 256 stringToCString(value)),
257 [0x00, 0x00])) 257 [0x00, 0x00]))
258 }); 258 });
259 259
......