]> granicus.if.org Git - taglib/commitdiff
Fix a wrong parameter for zlib.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 6 Jan 2015 08:20:03 +0000 (17:20 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 6 Jan 2015 09:45:42 +0000 (18:45 +0900)
z_stream.avail_in has to be the length of the input buffer.
It will fail when frameDataLength is smaller than the actual compressed data size.

taglib/mpeg/id3v2/id3v2frame.cpp
tests/data/compressed_id3_frame.mp3

index 5dc84971221804219f81993663644f2e715931e7..bee5375adfc90b8dceed9419944e02c3deb5f433 100644 (file)
@@ -32,7 +32,6 @@
 #endif
 
 #include <bitset>
-#include <cstring>
 
 #include <tdebug.h>
 #include <tstringlist.h>
@@ -255,13 +254,17 @@ ByteVector Frame::fieldData(const ByteVector &frameData) const
   if(d->header->compression() &&
      !d->header->encryption())
   {
-    z_stream stream;
-    ::memset(&stream, 0, sizeof(z_stream));
+    if(frameData.size() <= frameDataOffset) {
+      debug("Compressed frame doesn't have enough data to decode");
+      return ByteVector();
+    }
+
+    z_stream stream = {};
 
     if(inflateInit(&stream) != Z_OK)
       return ByteVector();
 
-    stream.avail_in = (uLongf) frameDataLength;
+    stream.avail_in = (uLongf) frameData.size() - frameDataOffset;
     stream.next_in = (Bytef *) frameData.data() + frameDataOffset;
 
     static const uint chunkSize = 1024;
index 60bc895633b1ce32894e54800f6aa65d4e2cb546..824d036fa4459e57ad671a8c3bb910e384b94ff2 100644 (file)
Binary files a/tests/data/compressed_id3_frame.mp3 and b/tests/data/compressed_id3_frame.mp3 differ