PDA

View Full Version : ID3v2 Invalid Tag size (Programming Help)


VolureDarkAngel
24th April 2002, 09:41
I have a small problem in your version of the ID3 v2 Tags

I am a programmer making an ID3 Tagger and went to the ID3 website to gather the specs for the tag format.

After careful research looking over the tag I have found that your Winamp 2.79 dows not use the ID3 tagging system Properly. In the size portion of the header it notes the tag is much Longer then the file

here is what I have done

1 Created a File containing Data "File Data"
2 Added the ID3v2 Tags to the file using the Winamp 2.79 Tag editor
3 Opened the newly tagged file in a hex editor

While looking over the tag I noticed this fatal flaw

Your header (As Follows)
4944 3303 0000 0000 0F6D
Does not represent the Tag at all

the file size is 2048 with "FileData" and everything but as you can see the tag says its size is 0F6D (3949). If I were to try to clear or change this tag I would efficently overwrite the beginning of the file. Now I understand for the most part 1901 Bytes is not a very significant portion of a file but if done repeatedly could diminish the file significantly. and say its just a companion file just of the tag. Opening past the end of the file could cause Program errors and Memory leaks if used improperly. Please help me understand and correct this problem. How would you trap and correct this is you were to encounter it ?

Thank you
I have encluded the MP3 in a text file for your view. you should check it in a hex editor not to damage the invalid characters by use in notepad or other editors.

chrisbolt
24th April 2002, 23:26
This is not a bug in Winamp, you didn't research carefully enough. If you read the ID3v2 spec (http://www.id3.org/id3v2.3.0.html#sec3.1) closely, you'll notice:The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is represented as $00 00 02 01.The most significant bit is zeroed to prevent the header from being mistaken as the MP3 sync. Since the most significant bit is ignored, you can't just convert it directly from hex to binary. If you did that, the example ($00 00 02 01) would come out to 513 bytes when it really should come out to 257 bytes.

If you want the code to find the size, here's some example code in PHP, but it should be easy to port: (this assumes $fp is the file descriptor of the mp3, and it's right at the position of the size portion of the id3v2 header)$bytes = array();
for ($i = 0; $i < 4; $i++)
$bytes[$i] = fgetc($fp);
$v2size = (
($bytes[0] << 21) |
($bytes[1] << 14) |
($bytes[2] << 7) |
($bytes[3] ));
(if the most significant bit wasn't ignored, the numbers would be 24, 16, 8)

VolureDarkAngel
25th April 2002, 12:25
Ok so this means

$0??????? per Byte ?
:igor:

chrisbolt
25th April 2002, 13:19
Yes.

VolureDarkAngel
25th April 2002, 21:00
I figured it out and I got the Size settings working right
But Winamp dosnt recognize any of my Tags. I even mimiced the Chr(0) Before the tag that Winamp likes to throw in there but to no avail Winamp wont read My Tags

It says they are there but wont display them. Perhaps they need to be in a specific order or something ?

It is about to make me blow a gasket

:mad:

VolureDarkAngel
25th April 2002, 21:05
I think I figured it out

VolureDarkAngel
25th April 2002, 22:32
Here is my Tagger it works now

Thanks a lot for your help

http://www.lokisystems.cjb.net/download

:winamp: :) :D :p ;) :) ;) :up: :D :cool: :) :winamp: