]> mj.ucw.cz Git - libucw.git/commitdiff
obj_read_bucket()
authorRobert Spalek <robert@ucw.cz>
Mon, 28 Jun 2004 12:00:38 +0000 (12:00 +0000)
committerRobert Spalek <robert@ucw.cz>
Mon, 28 Jun 2004 12:00:38 +0000 (12:00 +0000)
- never tampers the fastbuf when parsing the header
- the body might by tampered under very special (and well commented) conditions

lib/buck2obj.c
lib/buck2obj.h

index c0ee98c66af9486f34338353dfc4e0fec629b9a9..ba7efd57a143211ca6f98e00e410088c9685ee2c 100644 (file)
@@ -70,21 +70,6 @@ decode_attributes(byte *ptr, byte *end, struct odes *o, uns can_overwrite)
       ptr[len] = 0;
       obj_add_attr_ref(o, type, ptr);
 
-      ptr += len + 1;
-    }
-  else if (can_overwrite == 1)
-    while (ptr < end)
-    {
-      uns len;
-      GET_UTF8(ptr, len);
-      if (!len--)
-       break;
-      byte type = ptr[len];
-
-      ptr[len] = 0;
-      obj_add_attr(o, type, ptr);
-      ptr[len] = type;
-
       ptr += len + 1;
     }
   else
@@ -130,9 +115,6 @@ obj_read_bucket(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fa
     /* Read all the bucket into 1 buffer, 0-copy if possible.  */
     int can_overwrite = bconfig(body, BCONFIG_CAN_OVERWRITE, -1);
     /* FIXME: This could be cached in buck2obj_buf */
-    if (can_overwrite < 0)
-      can_overwrite = 0;
-    uns overwritten;
     byte *ptr, *end;
     uns len = bdirect_read_prepare(body, &ptr);
     if (len < buck_len
@@ -143,15 +125,11 @@ obj_read_bucket(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fa
       bb_grow(&buf->bb, buck_len);
       len = bread(body, buf->bb.ptr, buck_len);
       ptr = buf->bb.ptr;
-      can_overwrite = 2;
-      overwritten = 0;
     }
-    else
-      overwritten = can_overwrite > 1;
     end = ptr + len;
 
     byte *start = ptr;
-    ptr = decode_attributes(ptr, end, o, can_overwrite);// header
+    ptr = decode_attributes(ptr, end, o, 0);           // header
     if (body_start)
     {
       *body_start = ptr - start;
@@ -174,16 +152,16 @@ obj_read_bucket(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fa
       }
       ptr = new_ptr;
       end = ptr + len;
-      can_overwrite = 2;
     }
     else                                               // unknown bucket type
       RET_ERR(EINVAL);
-    ASSERT(can_overwrite == 2);                                // because of the policy and decompression
     ptr = decode_attributes(ptr, end, o, 2);           // body
 
     if (ptr != end)
       RET_ERR(EINVAL);
-    /* If (overwritten), bflush(body) might be needed.  */
+    /* If the bucket fit into the fastbuf buffer, can_overwrite == 2, and
+     * buck_type == BUCKET_TYPE_V33, then bflush(body) is needed before
+     * anything else than sequential read.  */
   }
   return o;
 }
index e83015cdecec42672b9317110acc557c5178a7c2..86762a8ec581f0c6d834305b8464191a7c74abdb 100644 (file)
@@ -12,9 +12,10 @@ void buck2obj_free(struct buck2obj_buf *buf);
 void buck2obj_flush(struct buck2obj_buf *buf);
 struct odes *obj_read_bucket(struct buck2obj_buf *buf, uns buck_type, uns buck_len, struct fastbuf *body, uns *body_start);
   /* If body_start != NULL, then only the header is parsed and *body_start is
-   * set to the position of the body.
+   * set to the position of the body.  The fastbuf is never overwritten when
+   * parsing a header.
    *
-   * If BCONFIG_CAN_OVERWRITE(body)==2, then the buffer of body has probably
-   * been tampered with (unless the bucket is larger than the buffer).  In such
-   * a case, you must call bflush(body) before you do anything else than
-   * sequential read.  */
+   * If !body_start && BCONFIG_CAN_OVERWRITE(body)==2, then the fastbuf might
+   * have been tampered with (unless the bucket is larger than the buffer or
+   * the bucket was compressed).  In such a case, you must call bflush(body)
+   * before you do anything else than sequential read.  */