From: Scott Wheeler Date: Mon, 18 Oct 2004 15:31:12 +0000 (+0000) Subject: Move the sanity check before the unknown frame stuff. As the code currently X-Git-Tag: v1.5~315 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d5ab8fd106623d9c4826d574cb6f16ba921d6fa;p=taglib Move the sanity check before the unknown frame stuff. As the code currently is if a bogus frame is hit it may try to parse it as an UnknownFrame rather than just discarding it. CCMAIL:Espen Tveit git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@355686 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- diff --git a/mpeg/id3v2/id3v2framefactory.cpp b/mpeg/id3v2/id3v2framefactory.cpp index 858e4637..88343c2b 100644 --- a/mpeg/id3v2/id3v2framefactory.cpp +++ b/mpeg/id3v2/id3v2framefactory.cpp @@ -67,6 +67,22 @@ Frame *FrameFactory::createFrame(const ByteVector &data, bool synchSafeInts) con Frame *FrameFactory::createFrame(const ByteVector &data, uint version) const { Frame::Header *header = new Frame::Header(data, version); + ByteVector frameID = header->frameID(); + + // A quick sanity check -- make sure that the frameID is 4 uppercase Latin1 + // characters. Also make sure that there is data in the frame. + + if(!frameID.size() == (version < 3 ? 3 : 4) || header->frameSize() <= 0) { + delete header; + return 0; + } + + for(ByteVector::ConstIterator it = frameID.begin(); it != frameID.end(); it++) { + if( (*it < 'A' || *it > 'Z') && (*it < '1' || *it > '9') ) { + delete header; + return 0; + } + } // TagLib doesn't mess with encrypted frames, so just treat them // as unknown frames. @@ -82,21 +98,6 @@ Frame *FrameFactory::createFrame(const ByteVector &data, uint version) const return new UnknownFrame(data, header); } - TagLib::ByteVector frameID = header->frameID(); - - // A quick sanity check -- make sure that the frameID is 4 uppercase Latin1 - // characters. Also make sure that there is data in the frame. - - if(!frameID.size() == (version < 3 ? 3 : 4) || header->frameSize() <= 0) - return 0; - - for(ByteVector::ConstIterator it = frameID.begin(); it != frameID.end(); it++) { - if( (*it < 'A' || *it > 'Z') && (*it < '1' || *it > '9') ) { - delete header; - return 0; - } - } - if(!updateFrame(header)) { delete header; return 0;