Trying to write tags back to MP3 file results in an
ArrayOutfBoundsException, here's some printouts:
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at helliker.id3.ID3v2Tag.getBytes(ID3v2Tag.java:337)
at helliker.id3.ID3v2Tag.writeTag(ID3v2Tag.java:230)
at helliker.id3.MP3File.writeTags(MP3File.java:436)
Logged In: NO
this problem is due to a bug when calculating padding. For
some reason the padding value is sometimes negative !
I couldnt find out why this happens, but added a clause in
ID3v2Tag.java which only uses a positive padding value and it
seems to have fixed this problem.
I will send the code shortly
scott pegler
spegler@uk.cintra.com
Logged In: YES
user_id=661657
If still have this problem:
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at helliker.id3.ID3v2Tag.getBytes(ID3v2Tag.java:369)
at helliker.id3.ID3v2Tag.writeTag(ID3v2Tag.java:270)
at helliker.id3.MP3File.writeTags(MP3File.java:477)
The code:
[line 367] // Bytes should all be zero's by default
[line 368] if (padding > 0) {
[line 369] System.arraycopy(new byte[padding], 0, b,
bytesCopied, padding);
[line 370] bytesCopied += padding;
[line 371] }
Jan van Oosterom
Logged In: YES
user_id=661657
what is the max size for padding 'cause I get padding = 31,
and that is to big I assume, because the array where the
data is going to (b) is not big enough.
Logged In: YES
user_id=661657
I made a little fix for this problem.
But I think this code needs a rewrite, it has is unclear
what happens with the variables (like padding/writtenpadding
etc) some are used as local variables in a method but are
"globals". I think further that the concept of padding is
used a bit weird here. It is suppossed to be empty space, in
case the tag's need some more space isn't it? So the size of
the tag should not depend on the size of the padding.
padding should just be filling the space if there is some
room left. Further all those methods:
getSize/getTotalSize/getUpdatedPadding just are confusing.
The method getTotalSize claims to return the total size, but
does not add the padding....?
It is confusing to me anyway.
Well the fix, so it works (not a nice fix more like a hack):
[line 368] if (padding > 0) { //hack start
if ((bytesCopied + padding) > b.length) {
padding = b.length - bytesCopied;
}//hack end
System.arraycopy(new byte[padding], 0, b, bytesCopied,
padding);
bytesCopied += padding;
}
Logged In: NO
From what I am seeing, this error is repeatable on the second
call to writeTags. It would appear that the second time
through, the value of padding is non-zero. However, the
sizing of the byte array b in the getBytes method never
accounts for a non-zero padding size. Hence, the call to
System.arraycopy inside the if(padding>0) block exceeds the
bounds of byte array b.