From ff8443f33a4d6c7a577b66048692f0471df76830 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 2 May 2015 02:34:40 +0900 Subject: [PATCH] Fix the wrong padding of ByteVector::resize(). The expanded area will be filled with garbage instead of correct padding in some corner cases. --- taglib/toolkit/tbytevector.cpp | 1 + tests/test_bytevector.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 4ae40666..bf6c525f 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -702,6 +702,7 @@ ByteVector &ByteVector::resize(uint size, char padding) { if(size != d->length) { detach(); + d->data->data.resize(d->offset + d->length); d->data->data.resize(d->offset + size, padding); d->length = size; } diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index c68a8c34..e9d43c05 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -123,6 +123,12 @@ public: CPPUNIT_ASSERT(i.containsAt(j, 5, 0)); CPPUNIT_ASSERT(i.containsAt(j, 6, 1)); CPPUNIT_ASSERT(i.containsAt(j, 6, 1, 3)); + + ByteVector k = ByteVector("0123456789").mid(3, 4); + k.resize(6, 'A'); + CPPUNIT_ASSERT_EQUAL(uint(6), k.size()); + CPPUNIT_ASSERT_EQUAL('6', k[3]); + CPPUNIT_ASSERT_EQUAL('A', k[4]); } void testFind1()