When decoding syncsafe integers, assume non-syncsafe integers are written by buggy software and treat them as normal integers.

From Songbird bug 12964, original author Mike Smith (msmith@songbirdnest.com)

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1056922 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Peter van Hardenberg 2009-12-01 09:11:21 +00:00
parent 1b6ab18080
commit 85df71ea2e

View File

@ -33,10 +33,26 @@ using namespace ID3v2;
TagLib::uint SynchData::toUInt(const ByteVector &data)
{
uint sum = 0;
bool notsyncsafe = false;
int last = data.size() > 4 ? 3 : data.size() - 1;
for(int i = 0; i <= last; i++)
for(int i = 0; i <= last; i++) {
if (data[i] & 0x80) {
notsyncsafe = true;
break;
}
sum |= (data[i] & 0x7f) << ((last - i) * 7);
}
if (notsyncsafe) {
/* Invalid data; assume this was created by some buggy software that just
* put normal integers here rather than syncsafe ones, and try it that
* way... */
sum = 0;
for(int i = 0; i <= last; i++)
sum |= data[i] << ((last - i) * 8);
}
return sum;
}