X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fbuck2obj.c;h=e90ff875447eead2125b08e7d8624804df20a612;hb=06a12f5259063aa66bb4d6d8b4226677f4849157;hp=15aac17474919ac691286b58828edfed16ce7ebe;hpb=90e4a2cc675da72059b655a7c0222ee03a9dd74a;p=libucw.git diff --git a/lib/buck2obj.c b/lib/buck2obj.c index 15aac174..e90ff875 100644 --- a/lib/buck2obj.c +++ b/lib/buck2obj.c @@ -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) { - 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; - 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); - 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 { - 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) @@ -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 (ptr + 4 > end) + if (ptr + 8 > end) RET_ERR(EINVAL); len = GET_U32(ptr); ptr += 4; @@ -181,13 +192,3 @@ obj_read(struct fastbuf *f, struct odes *o) } 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); -}