[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/taglib
From: Lukáš Lalinský <lalinsky () gmail ! com>
Date: 2009-07-28 18:29:39
Message-ID: 1248805779.676013.3663.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1003745 by lalinsky:
Handle RIFF chunk padding and ignore trailing garbage
This is based on patches by Marc Halbruegge, but those only deal with
read-only cases. The code now also correctly adds padding to RIFF
chunks, and calculates offsets in chunkData taking the padding into
account.
BUG:171957
BUG:175781
M +34 -4 taglib/riff/rifffile.cpp
M +4 -0 tests/CMakeLists.txt
AM tests/data/empty.aiff
AM tests/test_aiff.cpp [License: UNKNOWN]
AM tests/test_riff.cpp [License: UNKNOWN]
--- trunk/kdesupport/taglib/taglib/riff/rifffile.cpp #1003744:1003745
@@ -49,6 +49,7 @@
std::vector<ByteVector> chunkNames;
std::vector<uint> chunkOffsets;
std::vector<uint> chunkSizes;
+ std::vector<char> chunkPadding;
};
////////////////////////////////////////////////////////////////////////////////
@@ -101,7 +102,7 @@
long begin = 12 + 8;
for(uint it = 0; it < i; it++)
- begin += 8 + d->chunkSizes[it];
+ begin += 8 + d->chunkSizes[it] + d->chunkPadding[it];
seek(begin);
@@ -128,12 +129,15 @@
// Now update the specific chunk
- writeChunk(name, data, d->chunkOffsets[i] - 8, d->chunkSizes[i] + 8);
+ writeChunk(name, data, d->chunkOffsets[i] - 8, d->chunkSizes[i] + d->chunkPadding[i] + 8);
+ d->chunkSizes[i] = data.size();
+ d->chunkPadding[i] = (data.size() & 0x01) ? 1 : 0;
+
// Now update the internal offsets
for(i++; i < d->chunkNames.size(); i++)
- d->chunkOffsets[i] += sizeDifference;
+ d->chunkOffsets[i] = d->chunkOffsets[i-1] + 8 + d->chunkSizes[i-1] + d->chunkPadding[i-1];
return;
}
@@ -158,16 +162,38 @@
d->size = readBlock(4).toUInt(bigEndian);
d->format = readBlock(4);
- while(tell() < length()) {
+ // + 8: chunk header at least, fix for additional junk bytes
+ while(tell() + 8 <= length()) {
ByteVector chunkName = readBlock(4);
uint chunkSize = readBlock(4).toUInt(bigEndian);
+ if(tell() + chunkSize > length()) {
+ // something wrong
+ break;
+ }
+
d->chunkNames.push_back(chunkName);
d->chunkSizes.push_back(chunkSize);
d->chunkOffsets.push_back(tell());
seek(chunkSize, Current);
+
+ // check padding
+ char paddingSize = 0;
+ long uPosNotPadded = tell();
+ if((uPosNotPadded & 0x01) != 0) {
+ ByteVector iByte = readBlock(1);
+ if((iByte.size() != 1) || (iByte[0] != 0)) {
+ // not well formed, re-seek
+ seek(uPosNotPadded, Beginning);
+ }
+ else {
+ paddingSize = 1;
+ }
+ }
+ d->chunkPadding.push_back(paddingSize);
+
}
}
@@ -177,5 +203,9 @@
ByteVector combined = name;
combined.append(ByteVector::fromUInt(data.size(), d->endianness == BigEndian));
combined.append(data);
+ if((data.size() & 0x01) != 0) {
+ // padding
+ combined.append('\x00');
+ }
insert(combined, offset, replace);
}
--- trunk/kdesupport/taglib/tests/CMakeLists.txt #1003744:1003745
@@ -9,6 +9,8 @@
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg/id3v2/frames
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mpeg
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mp4
+ ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/riff
+ ${CMAKE_CURRENT_SOURCE_DIR}/../taglib/riff/aiff
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/trueaudio
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ogg
)
@@ -27,6 +29,8 @@
test_id3v1.cpp
test_id3v2.cpp
test_xiphcomment.cpp
+ test_aiff.cpp
+ test_riff.cpp
)
IF(WITH_MP4)
SET(test_runner_SRCS ${test_runner_SRCS} test_mp4.cpp)
** trunk/kdesupport/taglib/tests/data/empty.aiff #property svn:mime-type
+ application/octet-stream
** trunk/kdesupport/taglib/tests/test_aiff.cpp #property svn:eol-style
+ native
** trunk/kdesupport/taglib/tests/test_aiff.cpp #property svn:keywords
+ Id
** trunk/kdesupport/taglib/tests/test_riff.cpp #property svn:eol-style
+ native
** trunk/kdesupport/taglib/tests/test_riff.cpp #property svn:keywords
+ Id
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic