]> mj.ucw.cz Git - libucw.git/blobdiff - lib/lizard-fb.c
- bugfix: when disabling compression, change bucket_type
[libucw.git] / lib / lizard-fb.c
index 2a6d1749c796ea7ffc407ae1dc4074b547af1eed..5a5c20547f5653af7c331d9a78aa3eb9c45b9760 100644 (file)
@@ -30,7 +30,7 @@ lizard_bwrite(struct fastbuf *fb_out, byte *ptr_in, uns len_in)
   byte *ptr_out;
   uns len_out;
   uns type = liz_type;
-  if (type == BUCKET_TYPE_V33_LIZARD)
+  if (type == BUCKET_TYPE_V33_LIZARD && liz_min_compr)
   {
     uns est_out = len_in * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD + 16;
     uns aval_out = bdirect_write_prepare(fb_out, &ptr_out);
@@ -51,6 +51,8 @@ lizard_bwrite(struct fastbuf *fb_out, byte *ptr_in, uns len_in)
   }
   else
   {
+    if (type == BUCKET_TYPE_V33_LIZARD)
+      type = BUCKET_TYPE_V33;
     ptr_out = ptr_in;
     len_out = len_in;
   }
@@ -65,11 +67,11 @@ lizard_bwrite(struct fastbuf *fb_out, byte *ptr_in, uns len_in)
     bwrite(fb_out, ptr_out, len_out);
   else
     bdirect_write_commit(fb_out, ptr_out + len_out);
-  return len_out + 8 + (type == BUCKET_TYPE_V33_LIZARD ? 8 : 0);
+  return type;
 }
 
 int
-lizard_bbcopy(struct fastbuf *fb_out, struct fastbuf *fb_in, uns len_in)
+lizard_bbcopy_compress(struct fastbuf *fb_out, struct fastbuf *fb_in, uns len_in)
 {
   byte *ptr_in;
   uns i = bdirect_read_prepare(fb_in, &ptr_in);
@@ -105,6 +107,11 @@ int
 lizard_memread(struct lizard_buffer *liz_buf, byte *ptr_in, byte **ptr_out, uns *type)
 {
   *type = GET_U32(ptr_in);
+  if (*type < BUCKET_TYPE_PLAIN || *type > BUCKET_TYPE_V33_LIZARD)
+  {
+    errno = EINVAL;
+    return -1;
+  }
   uns stored_len = GET_U32(ptr_in + 4);
   ptr_in += 8;
   if (*type == BUCKET_TYPE_V33_LIZARD)
@@ -120,6 +127,14 @@ int
 lizard_bread(struct lizard_buffer *liz_buf, struct fastbuf *fb_in, byte **ptr_out, uns *type)
 {
   *type = bgetl(fb_in);
+  if (*type < BUCKET_TYPE_PLAIN || *type > BUCKET_TYPE_V33_LIZARD)
+  {
+    if (*type == ~0U)                  // EOF
+      errno = EBADF;
+    else
+      errno = EINVAL;
+    return -1;
+  }
   uns stored_len = bgetl(fb_in);
   uns want_len = stored_len + (*type == BUCKET_TYPE_V33_LIZARD ? 8 : 0);
   byte *ptr_in;