43081j / id3

A JavaScript ID3 tags parser for Node & browsers.
MIT License
335 stars 63 forks source link

getUint16 - Index out of range #6

Closed kvalium closed 9 years ago

kvalium commented 10 years ago

Processing files having a long name, the following error appears:

/home/pi/nodejs/snjsp/node_modules/id3js/dist/id3.js:231
                        var bomInt = this.getUint16(offset);
                                          ^
Error: Index out of range.
    at DataView.getStringUtf16 (/home/pi/nodejs/snjsp/node_modules/id3js/dist/id3.js:231:22)
    at Object.ID3Frame.parse (/home/pi/nodejs/snjsp/node_modules/id3js/dist/id3.js:668:24)
    at /home/pi/nodejs/snjsp/node_modules/id3js/dist/id3.js:943:24
    at /home/pi/nodejs/snjsp/node_modules/id3js/dist/id3.js:118:4
    at Object.wrapper [as oncomplete] (fs.js:454:17)

By example, this error occurs while reading tags for file in: /home/pi/music/dd/Aphrodites Child/1968 - End of the World/01 - End Of The World.mp3

Renaming the file of the folder with a shorter name solves the issue.

Regards,

kvalium

ntuckerxx commented 10 years ago

It's not always the filename length; it appears there's a general bug in the monkeypatched DataView.getStringUtf16. I debugged into it and found it choking on some headers with strings of encoding type 1. One or more of my files has a TCON frame with a 'size' of 1 and the payload is just a single byte of value 1, which is interpreted as the encoding type. Once getStringUtf16 decides encoding === 1, its next order of business is to read the BOM from an offset that's past the end of the buffer. I added a guard against this specific case:

    if(bom) {
        if(offset + 1 > this.byteLength) {
            return "";
        }
        ...

...but there should probably be some attention paid to this type of error in the actual string-reading loop as well (you can't trust that the frame length is actually big enough to read everything you expect from it).

Here's the example buffer: { '0': 84, '1': 67, '2': 79, '3': 78, '4': 0, '5': 0, '6': 0, '7': 1, '8': 0, '9': 0, '10': 1, byteLength: 11 }

kwv commented 10 years ago

+1 thanks for this. fixed what I was seeing too.

Captainlonate commented 9 years ago

So how do I fix this problem?

yashafromrussia commented 9 years ago

@Captainlonate, adding that guard @ntuckerxx is talking about seems to fix the problem (or at least avoid it). In DataView.prototype.getStringUtf16 where it's checking for bom flag, the if statement should be the following:

if(bom) {
  if(offset + 1 > this.byteLength) {
    return "";
  }
  var bomInt = this.getUint16(offset);
  if(bomInt === 0xFFFE) {
    littleEndian = true;
  }
  offset += 2;
  length -= 2;
}
43081j commented 9 years ago

This has been added in #27. It doesn't seem like the best way we could do it but at least it fixes the issue.

MaffooBristol commented 9 years ago

I'm still getting this with the patched branch and without having ridiculously long filenames. Not sure how to debug?

Although mine is that Offset is outside the bounds of the DataView error on the following lines, like the previous issue thread that has been duped to this:

if(dv.getUint8(i) === 0x00) {
  variableStart = i + 1;
  break;
}
UnshiftedEarth commented 9 years ago

Ok so how in the world do i fix it cause i am just a user and when i'm trying to launch a agar.io server and try to join it i don' t see anything, i get this error

RangeError: Offset is outside the bounds of the DataView

What do i do?

ZMYaro commented 1 year ago

I am not sure why, but I am getting the error again with a couple files.

util.js:65 Uncaught (in promise) RangeError: Offset is outside the bounds of the DataView
    at DataView.getUint16 (<anonymous>)
    at getStringUtf16 (util.js:65:18)
    at parse (id3Frame.js:257:19)
    at parse (id3Tag.js:117:37)
    at async fromReader (id3.js:15:18)
    at async form.onsubmit (asdf.js:66:13)

The tags of one of the files that produces the error are:

ALBUM: My Skateboard Will Go On (Single)
ALBUMARTIST: Anamanaguchi
ARTIST: Anamanaguchi
COMPOSER: Peter Berkman
DISCNUMBER: 1/1
GENRE: Chiptune
TITLE: My Skateboard Will Go On
TRACK: 01/02
YEAR: 2010

The file plays fine, both in my default media player, and if I point an <audio> element to the same file I pass to id3js. The tags show up fine as well, in my default media player, file browser, and the Mp3tag editor.