Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getUint16 - Index out of range #6

Closed
kvalium opened this issue Jan 19, 2014 · 8 comments · Fixed by #42
Closed

getUint16 - Index out of range #6

kvalium opened this issue Jan 19, 2014 · 8 comments · Fixed by #42

Comments

@kvalium
Copy link

kvalium commented Jan 19, 2014

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
Copy link

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
Copy link

kwv commented Jun 23, 2014

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

@Captainlonate
Copy link

So how do I fix this problem?

@yashafromrussia
Copy link

@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
Copy link
Owner

43081j commented May 24, 2015

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.

@43081j 43081j closed this as completed May 24, 2015
@MaffooBristol
Copy link

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
Copy link

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
Copy link

ZMYaro commented Feb 28, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants