Fix parsing of long frame lengths

This commit is contained in:
Noah Crocker 2015-06-02 21:20:53 -04:00
parent 3d3bc45fe1
commit ca295709d5

View File

@ -45,10 +45,7 @@ public class ID3v2File extends Common {
int id3v = ((b2be32(v2hdr,0))) & 0xFF; // swapped ID3\04 -> ver. ist the first byte
int v3len = ((b2be32(v2hdr,6))); // total size EXCLUDING the this 10 byte header
v3len = ((v3len & 0x7f000000) >> 3) | // for some funky reason, this is encoded as 7*4 bits
((v3len & 0x007f0000) >> 2) |
((v3len & 0x00007f00) >> 1) |
((v3len & 0x0000007f) >> 0) ;
v3len = unsyncsafe(v3len);
// debug(">> tag version ID3v2."+id3v);
// debug(">> LEN= "+v3len+" // "+v3len);
@ -59,6 +56,17 @@ public class ID3v2File extends Common {
tags.put("_hdrlen", v3len+v2hdr_len);
return tags;
}
/*
** converts syncsafe integer to Java integer
*/
private int unsyncsafe(int x) {
x = ((x & 0x7f000000) >> 3) |
((x & 0x007f0000) >> 2) |
((x & 0x00007f00) >> 1) |
((x & 0x0000007f) >> 0) ;
return x;
}
/* Parses all ID3v2 frames at the current position up until payload_len
** bytes were read
@ -72,6 +80,7 @@ public class ID3v2File extends Common {
bread += s.read(frame);
String framename = new String(frame, 0, 4);
int slen = b2be32(frame, 4);
slen = unsyncsafe(slen);
/* Abort on silly sizes */
if(slen < 1 || slen > 524288)