diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 9aaf76ef..1d834b04 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -23,13 +23,15 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ +#include +#include + #include #include #include #include "rifffile.h" -#include -#include +#include "riffutils.h" using namespace TagLib; @@ -175,7 +177,7 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo // Couldn't find an existing chunk, so let's create a new one. - uint i = d->chunks.size() - 1; + uint i = d->chunks.size() - 1; ulong offset = d->chunks[i].offset + d->chunks[i].size; // First we update the global size @@ -189,7 +191,7 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo // And update our internal structure - if (offset & 1) { + if(offset & 1) { d->chunks[i].padding = 1; offset++; } @@ -231,19 +233,6 @@ void RIFF::File::removeChunk(const ByteVector &name) // private members //////////////////////////////////////////////////////////////////////////////// -static bool isValidChunkID(const ByteVector &name) -{ - if(name.size() != 4) { - return false; - } - for(int i = 0; i < 4; i++) { - if(name[i] < 32 || name[i] > 127) { - return false; - } - } - return true; -} - void RIFF::File::read() { bool bigEndian = (d->endianness == BigEndian); @@ -257,7 +246,7 @@ void RIFF::File::read() ByteVector chunkName = readBlock(4); uint chunkSize = readBlock(4).toUInt(bigEndian); - if(!isValidChunkID(chunkName)) { + if(!isValidChunkName(chunkName)) { debug("RIFF::File::read() -- Chunk '" + chunkName + "' has invalid ID"); setValid(false); break; diff --git a/taglib/riff/riffutils.h b/taglib/riff/riffutils.h new file mode 100644 index 00000000..c9270dff --- /dev/null +++ b/taglib/riff/riffutils.h @@ -0,0 +1,55 @@ +/*************************************************************************** + copyright : (C) 2015 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#ifndef TAGLIB_RIFFUTILS_H +#define TAGLIB_RIFFUTILS_H + +// THIS FILE IS NOT A PART OF THE TAGLIB API + +#ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header + +namespace TagLib +{ + namespace RIFF + { + static bool isValidChunkName(const ByteVector &name) + { + if(name.size() != 4) + return false; + + for(ByteVector::ConstIterator it = name.begin(); it != name.end(); ++it) { + const uchar c = static_cast(*it); + if(c < 32 || 127 < c) + return false; + } + + return true; + } + } +} + +#endif + +#endif diff --git a/taglib/riff/wav/infotag.cpp b/taglib/riff/wav/infotag.cpp index dbd9395e..00d1f1c5 100644 --- a/taglib/riff/wav/infotag.cpp +++ b/taglib/riff/wav/infotag.cpp @@ -27,25 +27,13 @@ #include #include "infotag.h" +#include "riffutils.h" using namespace TagLib; using namespace RIFF::Info; namespace { - inline bool isValidChunkID(const ByteVector &name) - { - if(name.size() != 4) - return false; - - for(int i = 0; i < 4; i++) { - if(name[i] < 32 || name[i] > 127) - return false; - } - - return true; - } - const RIFF::Info::StringHandler defaultStringHandler; const RIFF::Info::StringHandler *stringHandler = &defaultStringHandler; } @@ -197,7 +185,7 @@ String RIFF::Info::Tag::fieldText(const ByteVector &id) const void RIFF::Info::Tag::setFieldText(const ByteVector &id, const String &s) { // id must be four-byte long pure ascii string. - if(!isValidChunkID(id)) + if(!isValidChunkName(id)) return; if(!s.isEmpty()) @@ -258,7 +246,7 @@ void RIFF::Info::Tag::parse(const ByteVector &data) break; const ByteVector id = data.mid(p, 4); - if(isValidChunkID(id)) { + if(isValidChunkName(id)) { const String text = stringHandler->parse(data.mid(p + 8, size)); d->fieldListMap[id] = text; }