namespace
{
- bool isKeyValid(const char *key, size_t length)
+ const unsigned int MinKeyLength = 2;
+ const unsigned int MaxKeyLength = 255;
+
+ bool isKeyValid(const ByteVector &key)
{
const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", 0 };
- if(length < 2 || length > 255)
- return false;
-
// only allow printable ASCII including space (32..126)
- for(const char *p = key; p < key + length; ++p) {
- const int c = static_cast<unsigned char>(*p);
+ for(ByteVector::ConstIterator it = key.begin(); it != key.end(); ++it) {
+ const int c = static_cast<unsigned char>(*it);
if(c < 32 || c > 126)
return false;
}
for(size_t i = 0; invalidKeys[i] != 0; ++i) {
- if(Utils::equalsIgnoreCase(key, invalidKeys[i]))
+ if(String(key).upper() == invalidKeys[i])
return false;
}
bool APE::Tag::checkKey(const String &key)
{
- if(!key.isLatin1())
+ if(key.size() < MinKeyLength || key.size() > MaxKeyLength)
return false;
- const std::string data = key.to8Bit(false);
- return isKeyValid(data.c_str(), data.size());
+ return isKeyValid(key.data(String::Latin1));
}
APE::Footer *APE::Tag::footer() const
const unsigned int keyLength = nullPos - pos - 8;
const unsigned int valLegnth = data.toUInt(pos, false);
- if(isKeyValid(&data[pos + 8], keyLength)){
+ if(keyLength >= MinKeyLength
+ && keyLength <= MaxKeyLength
+ && isKeyValid(data.mid(pos + 8, keyLength)))
+ {
APE::Item item;
item.parse(data.mid(pos));
return String();
}
- /*!
- * Converts the letter c to lower case, not depending on the locale.
- */
- inline int toLowerCase(char c)
- {
- if('A' <= c && c <= 'Z')
- return c + ('a' - 'A');
- else
- return c;
- }
-
- /*!
- * Returns whether the two strings s1 and s2 are equal, ignoring the case
- * of the characters. This only supports US-ASCII and does not depend on
- * the current locale.
- *
- * We took the trouble to define this one here, since there are some
- * incompatible variations of case insensitive strcmp().
- */
- inline bool equalsIgnoreCase(const char *s1, const char *s2)
- {
- while(*s1 != '\0' && *s2 != '\0' && toLowerCase(*s1) == toLowerCase(*s2)) {
- s1++;
- s2++;
- }
-
- return (*s1 == '\0' && *s2 == '\0');
- }
-
/*!
* The types of byte order of the running system.
*/