diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 2783d922..15f8cbaf 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -419,7 +419,7 @@ void Ogg::XiphComment::parse(const ByteVector &data) if(entry.startsWith("METADATA_BLOCK_PICTURE=")) { // Decode base64 picture data - ByteVector picturedata = entry.mid(23, entry.size()-23).fromBase64(); + ByteVector picturedata = ByteVector::fromBase64(entry.mid(23)); if(picturedata.size()==0) { debug("Empty picture data. Discarding content"); diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index eb559390..f18d2329 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -954,7 +954,7 @@ ByteVector ByteVector::toHex() const -ByteVector & ByteVector::fromBase64() +ByteVector ByteVector::fromBase64(const ByteVector & input) { static const unsigned char base64[256]={ 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, @@ -975,10 +975,12 @@ ByteVector & ByteVector::fromBase64() 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80 }; - detach(); - uint len = size(); - const unsigned char * src = (unsigned char*) data(); - unsigned char * dst = (unsigned char*) data(); + uint len = input.size(); + + ByteVector output(len); + + const unsigned char * src = (unsigned char*) input.data(); + unsigned char * dst = (unsigned char*)output.data(); while(4<=len) { if(base64[src[0]]==0x80) break; if(base64[src[1]]==0x80) break; @@ -1000,8 +1002,8 @@ ByteVector & ByteVector::fromBase64() src+=4; len-=4; } - resize(dst-(unsigned char*)data()); - return *this; + output.resize(dst-(unsigned char*)output.data()); + return output; } diff --git a/taglib/toolkit/tbytevector.h b/taglib/toolkit/tbytevector.h index 0f96c77f..4b669b9e 100644 --- a/taglib/toolkit/tbytevector.h +++ b/taglib/toolkit/tbytevector.h @@ -579,12 +579,9 @@ namespace TagLib { ByteVector toBase64() const; /*! - * Decodes the base64 encoded byte vector in-memory. Returns a reference - * to this vector. Calls detach before decoding. + * Decodes the base64 encoded byte vector. */ - ByteVector & fromBase64(); - - + static ByteVector fromBase64(const ByteVector &); protected: /* diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index 19f51518..18097adf 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -406,15 +406,15 @@ public: // Decode CPPUNIT_ASSERT_EQUAL(sempty, eempty.toBase64()); - CPPUNIT_ASSERT_EQUAL(s0, e0.fromBase64()); - CPPUNIT_ASSERT_EQUAL(s1, e1.fromBase64()); - CPPUNIT_ASSERT_EQUAL(s2, e2.fromBase64()); - CPPUNIT_ASSERT_EQUAL(s3, e3.fromBase64()); + CPPUNIT_ASSERT_EQUAL(s0, ByteVector::fromBase64(e0)); + CPPUNIT_ASSERT_EQUAL(s1, ByteVector::fromBase64(e1)); + CPPUNIT_ASSERT_EQUAL(s2, ByteVector::fromBase64(e2)); + CPPUNIT_ASSERT_EQUAL(s3, ByteVector::fromBase64(e3)); - CPPUNIT_ASSERT_EQUAL(t0, s0.toBase64().fromBase64()); - CPPUNIT_ASSERT_EQUAL(t1, s1.toBase64().fromBase64()); - CPPUNIT_ASSERT_EQUAL(t2, s2.toBase64().fromBase64()); - CPPUNIT_ASSERT_EQUAL(t3, s3.toBase64().fromBase64()); + CPPUNIT_ASSERT_EQUAL(t0, ByteVector::fromBase64(s0.toBase64())); + CPPUNIT_ASSERT_EQUAL(t1, ByteVector::fromBase64(s1.toBase64())); + CPPUNIT_ASSERT_EQUAL(t2, ByteVector::fromBase64(s2.toBase64())); + CPPUNIT_ASSERT_EQUAL(t3, ByteVector::fromBase64(s3.toBase64())); }