]> mj.ucw.cz Git - libucw.git/blobdiff - lib/buck2obj.c
Parsing of PLAIN type buckets also ends after buck_len bytes.
[libucw.git] / lib / buck2obj.c
index 15aac17474919ac691286b58828edfed16ce7ebe..e90ff875447eead2125b08e7d8624804df20a612 100644 (file)
@@ -83,22 +83,33 @@ decode_attributes(byte *ptr, byte *end, struct odes *o, uns can_overwrite)
 int
 buck2obj_parse(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fastbuf *body, struct odes *o_hdr, uns *body_start, struct odes *o_body)
 {
 int
 buck2obj_parse(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fastbuf *body, struct odes *o_hdr, uns *body_start, struct odes *o_body)
 {
-  if (buck_type == BUCKET_TYPE_PLAIN)
+  if (buck_type <= BUCKET_TYPE_PLAIN)
   {
   {
-    if (body_start)
+    if (body_start)                    // there is no header part
       *body_start = 0;
       *body_start = 0;
-    obj_read_multi(body, o_hdr);       // ignore empty lines, read until EOF or NUL
+    // ignore empty lines and read until the end of the bucket
+    sh_off_t end = btell(body) + buck_len;
+    byte buf[MAX_ATTR_SIZE];
+    while (btell(body) < end && bgets(body, buf, sizeof(buf)))
+      if (buf[0])
+       obj_add_attr(o_hdr, buf[0], buf+1);
+    ASSERT(btell(body) == end);
   }
   else if (buck_type == BUCKET_TYPE_V30)
   {
     sh_off_t start = btell(body);
   }
   else if (buck_type == BUCKET_TYPE_V30)
   {
     sh_off_t start = btell(body);
-    obj_read(body, o_hdr);             // end on EOF or the first empty line
+    sh_off_t end = start + buck_len;
+    byte buf[MAX_ATTR_SIZE];
+    while (btell(body) < end && bgets(body, buf, sizeof(buf)) && buf[0])
+      obj_add_attr(o_hdr, buf[0], buf+1);
     if (body_start)
       *body_start = btell(body) - start;
     else
     {
     if (body_start)
       *body_start = btell(body) - start;
     else
     {
-      obj_read(body, o_body);
-      bgetc(body);
+      while (btell(body) < end && bgets(body, buf, sizeof(buf)))
+       if (buf[0])
+         obj_add_attr(o_hdr, buf[0], buf+1);
+      ASSERT(btell(body) == end);
     }
   }
   else if (buck_type == BUCKET_TYPE_V33 || buck_type == BUCKET_TYPE_V33_LIZARD)
     }
   }
   else if (buck_type == BUCKET_TYPE_V33 || buck_type == BUCKET_TYPE_V33_LIZARD)
@@ -130,7 +141,7 @@ buck2obj_parse(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fas
     }
     if (buck_type == BUCKET_TYPE_V33_LIZARD)           // decompression
     {
     }
     if (buck_type == BUCKET_TYPE_V33_LIZARD)           // decompression
     {
-      if (ptr + 4 > end)
+      if (ptr + 8 > end)
        RET_ERR(EINVAL);
       len = GET_U32(ptr);
       ptr += 4;
        RET_ERR(EINVAL);
       len = GET_U32(ptr);
       ptr += 4;
@@ -181,13 +192,3 @@ obj_read(struct fastbuf *f, struct odes *o)
     }
   return 0;
 }
     }
   return 0;
 }
-
-void
-obj_read_multi(struct fastbuf *f, struct odes *o)
-{
-  /* Read a multi-part object ending with either EOF or a NUL character */
-  byte buf[MAX_ATTR_SIZE];
-  while (bpeekc(f) > 0 && bgets(f, buf, sizeof(buf)))
-    if (buf[0])
-      obj_add_attr(o, buf[0], buf+1);
-}