]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
zlib: fix error on partial compression of files. Fixes #1902.
authorAdam Sutton <dev@adamsutton.me.uk>
Wed, 1 Jan 2014 12:48:39 +0000 (12:48 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Wed, 1 Jan 2014 12:48:39 +0000 (12:48 +0000)
This occurs where compressing small, already compressd files, typically images.

I could avoid compression of very small (or already compressed) files. But its
simple to keep things uniform and fixing this makes sense anyway!

src/filebundle.c

index 60ae966c80270473b4d391c381a0672098fe1740..97e05e30a77a31f8b6f99bfae160b93fb33ebfae 100644 (file)
@@ -127,12 +127,25 @@ static uint8_t *_fb_deflate ( const uint8_t *data, size_t orig, size_t *size )
   zstr.next_out  = bufout;
     
   /* Decompress */
-  err = deflate(&zstr, Z_FINISH);
-  if ( (err != Z_STREAM_END && err != Z_OK) || zstr.total_out == 0 ) {
-    free(bufout);
-    bufout = NULL;
-  } else {
-    *size  = zstr.total_out;
+  while (1) {
+    err = deflate(&zstr, Z_FINISH);
+
+    /* Need more space */
+    if (err == Z_OK && zstr.avail_out == 0) {
+      bufout         = realloc(bufout, zstr.total_out * 2);
+      zstr.avail_out = zstr.total_out;
+      zstr.next_out  = bufout + zstr.total_out;
+      continue;
+    }
+
+    /* Error */
+    if ( (err != Z_STREAM_END && err != Z_OK) || zstr.total_out == 0 ) {
+      free(bufout);
+      bufout = NULL;
+    } else {
+      *size  = zstr.total_out;
+    }
+    break;
   }
   free(bufin);
   deflateEnd(&zstr);