#include "lib/lib.h"
#include "lib/unaligned.h"
-#include "lib/pools.h"
+#include "lib/mempool.h"
#include "lib/fastbuf.h"
#include "lib/unicode.h"
#include "lib/object.h"
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)
}
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;
+ uns adler = GET_U32(ptr);
+ ptr += 4;
byte *new_ptr = lizard_decompress_safe(ptr, buf->lizard, len);
if (!new_ptr)
return -1;
+ if (adler32(new_ptr, len) != adler)
+ RET_ERR(EINVAL);
if (!copied)
bdirect_read_commit(body, end);
ptr = new_ptr;
else
return o;
}
+
+int
+obj_read(struct fastbuf *f, struct odes *o)
+{
+ byte buf[MAX_ATTR_SIZE];
+
+ while (bgets(f, buf, sizeof(buf)))
+ {
+ if (!buf[0])
+ return 1;
+ obj_add_attr(o, buf[0], buf+1);
+ }
+ return 0;
+}