Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/stat.h>
18 #include <sys/queue.h>
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sha1.h>
25 #include <zlib.h>
26 #include <ctype.h>
27 #include <limits.h>
29 #include "got_error.h"
30 #include "got_object.h"
31 #include "got_repository.h"
33 #include "got_lib_sha1.h"
34 #include "got_lib_delta.h"
35 #include "got_lib_pack.h"
36 #include "got_lib_zbuf.h"
37 #include "got_lib_object.h"
39 #ifndef MIN
40 #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
41 #endif
43 #ifndef nitems
44 #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
45 #endif
47 #define GOT_OBJ_TAG_COMMIT "commit"
48 #define GOT_OBJ_TAG_TREE "tree"
49 #define GOT_OBJ_TAG_BLOB "blob"
51 #define GOT_COMMIT_TAG_TREE "tree "
52 #define GOT_COMMIT_TAG_PARENT "parent "
53 #define GOT_COMMIT_TAG_AUTHOR "author "
54 #define GOT_COMMIT_TAG_COMMITTER "committer "
56 const struct got_error *
57 got_object_id_str(char **outbuf, struct got_object_id *id)
58 {
59 static const size_t len = SHA1_DIGEST_STRING_LENGTH;
61 *outbuf = calloc(1, len);
62 if (*outbuf == NULL)
63 return got_error_from_errno();
65 if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) {
66 free(*outbuf);
67 *outbuf = NULL;
68 return got_error(GOT_ERR_BAD_OBJ_ID_STR);
69 }
71 return NULL;
72 }
74 int
75 got_object_id_cmp(struct got_object_id *id1, struct got_object_id *id2)
76 {
77 return memcmp(id1->sha1, id2->sha1, SHA1_DIGEST_LENGTH);
78 }
80 struct got_object_id *
81 got_object_id_dup(struct got_object_id *id1)
82 {
83 struct got_object_id *id2;
85 id2 = malloc(sizeof(*id2));
86 if (id2 == NULL)
87 return NULL;
88 memcpy(id2, id1, sizeof(*id2));
89 return id2;
90 }
92 int
93 got_object_get_type(struct got_object *obj)
94 {
95 switch (obj->type) {
96 case GOT_OBJ_TYPE_COMMIT:
97 case GOT_OBJ_TYPE_TREE:
98 case GOT_OBJ_TYPE_BLOB:
99 case GOT_OBJ_TYPE_TAG:
100 return obj->type;
101 default:
102 abort();
103 break;
106 /* not reached */
107 return 0;
110 static const struct got_error *
111 parse_object_header(struct got_object **obj, char *buf, size_t len)
113 const char *obj_tags[] = {
114 GOT_OBJ_TAG_COMMIT,
115 GOT_OBJ_TAG_TREE,
116 GOT_OBJ_TAG_BLOB
117 };
118 const int obj_types[] = {
119 GOT_OBJ_TYPE_COMMIT,
120 GOT_OBJ_TYPE_TREE,
121 GOT_OBJ_TYPE_BLOB,
122 };
123 int type = 0;
124 size_t size = 0, hdrlen = 0;
125 int i;
126 char *p = strchr(buf, '\0');
128 if (p == NULL)
129 return got_error(GOT_ERR_BAD_OBJ_HDR);
131 hdrlen = strlen(buf) + 1 /* '\0' */;
133 for (i = 0; i < nitems(obj_tags); i++) {
134 const char *tag = obj_tags[i];
135 size_t tlen = strlen(tag);
136 const char *errstr;
138 if (strncmp(buf, tag, tlen) != 0)
139 continue;
141 type = obj_types[i];
142 if (len <= tlen)
143 return got_error(GOT_ERR_BAD_OBJ_HDR);
144 size = strtonum(buf + tlen, 0, LONG_MAX, &errstr);
145 if (errstr != NULL)
146 return got_error(GOT_ERR_BAD_OBJ_HDR);
147 break;
150 if (type == 0)
151 return got_error(GOT_ERR_BAD_OBJ_HDR);
153 *obj = calloc(1, sizeof(**obj));
154 if (*obj == NULL)
155 return got_error_from_errno();
156 (*obj)->type = type;
157 (*obj)->hdrlen = hdrlen;
158 (*obj)->size = size;
159 return NULL;
162 static const struct got_error *
163 read_object_header(struct got_object **obj, struct got_repository *repo,
164 FILE *f)
166 const struct got_error *err;
167 struct got_zstream_buf zb;
168 char *buf;
169 const size_t zbsize = 64;
170 size_t outlen, totlen;
171 int i;
173 buf = calloc(zbsize, sizeof(char));
174 if (buf == NULL)
175 return got_error_from_errno();
177 err = got_inflate_init(&zb, NULL, zbsize);
178 if (err)
179 return err;
181 i = 0;
182 totlen = 0;
183 do {
184 err = got_inflate_read(&zb, f, &outlen);
185 if (err)
186 goto done;
187 if (strchr(zb.outbuf, '\0') == NULL) {
188 buf = recallocarray(buf, 1 + i, 2 + i, zbsize);
189 if (buf == NULL) {
190 err = got_error_from_errno();
191 goto done;
194 memcpy(buf + totlen, zb.outbuf, outlen);
195 totlen += outlen;
196 i++;
197 } while (strchr(zb.outbuf, '\0') == NULL);
199 err = parse_object_header(obj, buf, totlen);
200 done:
201 got_inflate_end(&zb);
202 return err;
205 static const struct got_error *
206 object_path(char **path, struct got_object_id *id, struct got_repository *repo)
208 const struct got_error *err = NULL;
209 char *hex;
210 char *path_objects = got_repo_get_path_objects(repo);
212 if (path_objects == NULL)
213 return got_error_from_errno();
215 err = got_object_id_str(&hex, id);
216 if (err)
217 return err;
219 if (asprintf(path, "%s/%.2x/%s", path_objects,
220 id->sha1[0], hex + 2) == -1)
221 err = got_error_from_errno();
223 free(hex);
224 free(path_objects);
225 return err;
228 static const struct got_error *
229 open_loose_object(FILE **f, struct got_object *obj, struct got_repository *repo)
231 const struct got_error *err = NULL;
232 char *path;
234 err = object_path(&path, &obj->id, repo);
235 if (err)
236 return err;
237 *f = fopen(path, "rb");
238 if (*f == NULL) {
239 err = got_error_from_errno();
240 goto done;
242 done:
243 free(path);
244 return err;
247 const struct got_error *
248 got_object_open(struct got_object **obj, struct got_repository *repo,
249 struct got_object_id *id)
251 const struct got_error *err = NULL;
252 char *path;
253 FILE *f;
255 err = object_path(&path, id, repo);
256 if (err)
257 return err;
259 f = fopen(path, "rb");
260 if (f == NULL) {
261 if (errno != ENOENT) {
262 err = got_error_from_errno();
263 goto done;
265 err = got_packfile_open_object(obj, id, repo);
266 if (err)
267 goto done;
268 if (*obj == NULL)
269 err = got_error(GOT_ERR_NO_OBJ);
270 } else {
271 err = read_object_header(obj, repo, f);
272 if (err)
273 goto done;
274 memcpy((*obj)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
276 done:
277 free(path);
278 if (f)
279 fclose(f);
280 return err;
284 const struct got_error *
285 got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
286 const char *id_str)
288 struct got_object_id id;
290 if (!got_parse_sha1_digest(id.sha1, id_str))
291 return got_error(GOT_ERR_BAD_OBJ_ID_STR);
293 return got_object_open(obj, repo, &id);
296 void
297 got_object_close(struct got_object *obj)
299 if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
300 struct got_delta *delta;
301 while (!SIMPLEQ_EMPTY(&obj->deltas.entries)) {
302 delta = SIMPLEQ_FIRST(&obj->deltas.entries);
303 SIMPLEQ_REMOVE_HEAD(&obj->deltas.entries, entry);
304 got_delta_close(delta);
307 if (obj->flags & GOT_OBJ_FLAG_PACKED)
308 free(obj->path_packfile);
309 free(obj);
312 static const struct got_error *
313 parse_commit_object(struct got_commit_object **commit, char *buf, size_t len)
315 const struct got_error *err = NULL;
316 char *s = buf;
317 size_t tlen;
318 ssize_t remain = (ssize_t)len;
320 *commit = calloc(1, sizeof(**commit));
321 if (*commit == NULL)
322 return got_error_from_errno();
323 (*commit)->tree_id = calloc(1, sizeof(*(*commit)->tree_id));
324 if ((*commit)->tree_id == NULL) {
325 err = got_error_from_errno();
326 free(*commit);
327 *commit = NULL;
328 return err;
331 SIMPLEQ_INIT(&(*commit)->parent_ids);
333 tlen = strlen(GOT_COMMIT_TAG_TREE);
334 if (strncmp(s, GOT_COMMIT_TAG_TREE, tlen) == 0) {
335 remain -= tlen;
336 if (remain < SHA1_DIGEST_STRING_LENGTH) {
337 err = got_error(GOT_ERR_BAD_OBJ_DATA);
338 goto done;
340 s += tlen;
341 if (!got_parse_sha1_digest((*commit)->tree_id->sha1, s)) {
342 err = got_error(GOT_ERR_BAD_OBJ_DATA);
343 goto done;
345 remain -= SHA1_DIGEST_STRING_LENGTH;
346 s += SHA1_DIGEST_STRING_LENGTH;
347 } else {
348 err = got_error(GOT_ERR_BAD_OBJ_DATA);
349 goto done;
352 tlen = strlen(GOT_COMMIT_TAG_PARENT);
353 while (strncmp(s, GOT_COMMIT_TAG_PARENT, tlen) == 0) {
354 struct got_parent_id *pid;
356 remain -= tlen;
357 if (remain < SHA1_DIGEST_STRING_LENGTH) {
358 err = got_error(GOT_ERR_BAD_OBJ_DATA);
359 goto done;
362 pid = calloc(1, sizeof(*pid));
363 if (pid == NULL) {
364 err = got_error_from_errno();
365 goto done;
367 pid->id = calloc(1, sizeof(*pid->id));
368 if (pid->id == NULL) {
369 err = got_error_from_errno();
370 free(pid);
371 goto done;
373 s += tlen;
374 if (!got_parse_sha1_digest(pid->id->sha1, s)) {
375 err = got_error(GOT_ERR_BAD_OBJ_DATA);
376 free(pid->id);
377 free(pid);
378 goto done;
380 SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, pid, entry);
381 (*commit)->nparents++;
383 remain -= SHA1_DIGEST_STRING_LENGTH;
384 s += SHA1_DIGEST_STRING_LENGTH;
387 tlen = strlen(GOT_COMMIT_TAG_AUTHOR);
388 if (strncmp(s, GOT_COMMIT_TAG_AUTHOR, tlen) == 0) {
389 char *p;
391 remain -= tlen;
392 if (remain <= 0) {
393 err = got_error(GOT_ERR_BAD_OBJ_DATA);
394 goto done;
396 s += tlen;
397 p = strchr(s, '\n');
398 if (p == NULL) {
399 err = got_error(GOT_ERR_BAD_OBJ_DATA);
400 goto done;
402 *p = '\0';
403 (*commit)->author = strdup(s);
404 if ((*commit)->author == NULL) {
405 err = got_error_from_errno();
406 goto done;
408 s += strlen((*commit)->author) + 1;
409 remain -= strlen((*commit)->author) + 1;
412 tlen = strlen(GOT_COMMIT_TAG_COMMITTER);
413 if (strncmp(s, GOT_COMMIT_TAG_COMMITTER, tlen) == 0) {
414 char *p;
416 remain -= tlen;
417 if (remain <= 0) {
418 err = got_error(GOT_ERR_BAD_OBJ_DATA);
419 goto done;
421 s += tlen;
422 p = strchr(s, '\n');
423 if (p == NULL) {
424 err = got_error(GOT_ERR_BAD_OBJ_DATA);
425 goto done;
427 *p = '\0';
428 (*commit)->committer = strdup(s);
429 if ((*commit)->committer == NULL) {
430 err = got_error_from_errno();
431 goto done;
433 s += strlen((*commit)->committer) + 1;
434 remain -= strlen((*commit)->committer) + 1;
437 (*commit)->logmsg = strndup(s, remain);
438 if ((*commit)->logmsg == NULL) {
439 err = got_error_from_errno();
440 goto done;
442 done:
443 if (err) {
444 got_object_commit_close(*commit);
445 *commit = NULL;
447 return err;
450 static void
451 tree_entry_close(struct got_tree_entry *te)
453 free(te->id);
454 free(te->name);
455 free(te);
458 static const struct got_error *
459 parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
460 size_t maxlen)
462 char *p = buf, *space;
463 const struct got_error *err = NULL;
465 *te = calloc(1, sizeof(**te));
466 if (*te == NULL)
467 return got_error_from_errno();
469 (*te)->id = calloc(1, sizeof(*(*te)->id));
470 if ((*te)->id == NULL) {
471 err = got_error_from_errno();
472 free(*te);
473 *te = NULL;
474 return err;
477 *elen = strlen(buf) + 1;
478 if (*elen > maxlen) {
479 free(*te);
480 *te = NULL;
481 return got_error(GOT_ERR_BAD_OBJ_DATA);
484 space = strchr(buf, ' ');
485 if (space == NULL) {
486 err = got_error(GOT_ERR_BAD_OBJ_DATA);
487 free(*te);
488 *te = NULL;
489 return err;
491 while (*p != ' ') {
492 if (*p < '0' && *p > '7') {
493 err = got_error(GOT_ERR_BAD_OBJ_DATA);
494 goto done;
496 (*te)->mode <<= 3;
497 (*te)->mode |= *p - '0';
498 p++;
501 (*te)->name = strdup(space + 1);
502 if (*elen > maxlen || maxlen - *elen < SHA1_DIGEST_LENGTH) {
503 err = got_error(GOT_ERR_BAD_OBJ_DATA);
504 goto done;
506 buf += strlen(buf) + 1;
507 memcpy((*te)->id->sha1, buf, SHA1_DIGEST_LENGTH);
508 *elen += SHA1_DIGEST_LENGTH;
509 done:
510 if (err) {
511 tree_entry_close(*te);
512 *te = NULL;
514 return err;
517 static const struct got_error *
518 parse_tree_object(struct got_tree_object **tree, struct got_repository *repo,
519 uint8_t *buf, size_t len)
521 const struct got_error *err;
522 size_t remain = len;
524 *tree = calloc(1, sizeof(**tree));
525 if (*tree == NULL)
526 return got_error_from_errno();
528 SIMPLEQ_INIT(&(*tree)->entries);
530 while (remain > 0) {
531 struct got_tree_entry *te;
532 size_t elen;
534 err = parse_tree_entry(&te, &elen, buf, remain);
535 if (err)
536 return err;
537 (*tree)->nentries++;
538 SIMPLEQ_INSERT_TAIL(&(*tree)->entries, te, entry);
539 buf += elen;
540 remain -= elen;
543 if (remain != 0) {
544 got_object_tree_close(*tree);
545 return got_error(GOT_ERR_BAD_OBJ_DATA);
548 return NULL;
551 static const struct got_error *
552 read_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
554 const struct got_error *err = NULL;
555 static const size_t blocksize = 512;
556 size_t n, total, remain;
557 uint8_t *buf;
559 *outbuf = NULL;
560 *outlen = 0;
562 buf = calloc(1, blocksize);
563 if (buf == NULL)
564 return got_error_from_errno();
566 remain = blocksize;
567 total = 0;
568 while (1) {
569 if (remain == 0) {
570 uint8_t *newbuf;
571 newbuf = reallocarray(buf, 1, total + blocksize);
572 if (newbuf == NULL) {
573 err = got_error_from_errno();
574 goto done;
576 buf = newbuf;
577 remain += blocksize;
579 n = fread(buf + total, 1, remain, f);
580 if (n == 0) {
581 if (ferror(f)) {
582 err = got_ferror(f, GOT_ERR_IO);
583 goto done;
585 break; /* EOF */
587 remain -= n;
588 total += n;
589 };
591 done:
592 if (err == NULL) {
593 *outbuf = buf;
594 *outlen = total;
595 } else
596 free(buf);
597 return err;
600 static const struct got_error *
601 read_commit_object(struct got_commit_object **commit,
602 struct got_repository *repo, struct got_object *obj, FILE *f)
604 const struct got_error *err = NULL;
605 size_t len;
606 uint8_t *p;
608 if (obj->flags & GOT_OBJ_FLAG_PACKED)
609 err = read_to_mem(&p, &len, f);
610 else
611 err = got_inflate_to_mem(&p, &len, f);
612 if (err)
613 return err;
615 if (len < obj->hdrlen + obj->size) {
616 err = got_error(GOT_ERR_BAD_OBJ_DATA);
617 goto done;
620 /* Skip object header. */
621 len -= obj->hdrlen;
622 err = parse_commit_object(commit, p + obj->hdrlen, len);
623 free(p);
624 done:
625 return err;
628 const struct got_error *
629 got_object_commit_open(struct got_commit_object **commit,
630 struct got_repository *repo, struct got_object *obj)
632 const struct got_error *err = NULL;
634 if (obj->type != GOT_OBJ_TYPE_COMMIT)
635 return got_error(GOT_ERR_OBJ_TYPE);
637 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
638 uint8_t *buf;
639 size_t len;
640 err = got_packfile_extract_object_to_mem(&buf, &len, obj, repo);
641 if (err)
642 return err;
643 obj->size = len;
644 err = parse_commit_object(commit, buf, len);
645 free(buf);
646 } else {
647 FILE *f;
648 err = open_loose_object(&f, obj, repo);
649 if (err)
650 return err;
651 err = read_commit_object(commit, repo, obj, f);
652 fclose(f);
654 return err;
657 void
658 got_object_commit_close(struct got_commit_object *commit)
660 struct got_parent_id *pid;
662 while (!SIMPLEQ_EMPTY(&commit->parent_ids)) {
663 pid = SIMPLEQ_FIRST(&commit->parent_ids);
664 SIMPLEQ_REMOVE_HEAD(&commit->parent_ids, entry);
665 free(pid->id);
666 free(pid);
669 free(commit->tree_id);
670 free(commit->author);
671 free(commit->committer);
672 free(commit->logmsg);
673 free(commit);
676 static const struct got_error *
677 read_tree_object(struct got_tree_object **tree,
678 struct got_repository *repo, struct got_object *obj, FILE *f)
680 const struct got_error *err = NULL;
681 size_t len;
682 uint8_t *p;
684 if (obj->flags & GOT_OBJ_FLAG_PACKED)
685 err = read_to_mem(&p, &len, f);
686 else
687 err = got_inflate_to_mem(&p, &len, f);
688 if (err)
689 return err;
691 if (len < obj->hdrlen + obj->size) {
692 err = got_error(GOT_ERR_BAD_OBJ_DATA);
693 goto done;
696 /* Skip object header. */
697 len -= obj->hdrlen;
698 err = parse_tree_object(tree, repo, p + obj->hdrlen, len);
699 free(p);
700 done:
701 return err;
704 const struct got_error *
705 got_object_tree_open(struct got_tree_object **tree,
706 struct got_repository *repo, struct got_object *obj)
708 const struct got_error *err = NULL;
710 if (obj->type != GOT_OBJ_TYPE_TREE)
711 return got_error(GOT_ERR_OBJ_TYPE);
713 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
714 uint8_t *buf;
715 size_t len;
716 err = got_packfile_extract_object_to_mem(&buf, &len, obj, repo);
717 if (err)
718 return err;
719 obj->size = len;
720 err = parse_tree_object(tree, repo, buf, len);
721 free(buf);
722 } else {
723 FILE *f;
724 err = open_loose_object(&f, obj, repo);
725 if (err)
726 return err;
727 err = read_tree_object(tree, repo, obj, f);
728 fclose(f);
730 return err;
733 void
734 got_object_tree_close(struct got_tree_object *tree)
736 struct got_tree_entry *te;
738 while (!SIMPLEQ_EMPTY(&tree->entries)) {
739 te = SIMPLEQ_FIRST(&tree->entries);
740 SIMPLEQ_REMOVE_HEAD(&tree->entries, entry);
741 tree_entry_close(te);
744 free(tree);
747 const struct got_error *
748 got_object_blob_open(struct got_blob_object **blob,
749 struct got_repository *repo, struct got_object *obj, size_t blocksize)
751 const struct got_error *err = NULL;
753 if (obj->type != GOT_OBJ_TYPE_BLOB)
754 return got_error(GOT_ERR_OBJ_TYPE);
756 if (blocksize < obj->hdrlen)
757 return got_error(GOT_ERR_NO_SPACE);
759 *blob = calloc(1, sizeof(**blob));
760 if (*blob == NULL)
761 return got_error_from_errno();
763 if (obj->flags & GOT_OBJ_FLAG_PACKED) {
764 (*blob)->read_buf = calloc(1, blocksize);
765 if ((*blob)->read_buf == NULL) {
766 err = got_error_from_errno();
767 free(*blob);
768 *blob = NULL;
769 return err;
771 err = got_packfile_extract_object(&((*blob)->f), obj, repo);
772 if (err) {
773 free((*blob)->read_buf);
774 free(*blob);
775 *blob = NULL;
776 return err;
778 } else {
779 err = open_loose_object(&((*blob)->f), obj, repo);
780 if (err) {
781 free(*blob);
782 *blob = NULL;
783 return err;
786 err = got_inflate_init(&(*blob)->zb, NULL, blocksize);
787 if (err != NULL) {
788 fclose((*blob)->f);
789 free(*blob);
790 *blob = NULL;
791 return err;
794 (*blob)->read_buf = (*blob)->zb.outbuf;
795 (*blob)->flags |= GOT_BLOB_F_COMPRESSED;
798 (*blob)->hdrlen = obj->hdrlen;
799 (*blob)->blocksize = blocksize;
800 memcpy(&(*blob)->id.sha1, obj->id.sha1, SHA1_DIGEST_LENGTH);
802 return err;
805 void
806 got_object_blob_close(struct got_blob_object *blob)
808 if (blob->flags & GOT_BLOB_F_COMPRESSED)
809 got_inflate_end(&blob->zb);
810 else
811 free(blob->read_buf);
812 fclose(blob->f);
813 free(blob);
816 char *
817 got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
819 return got_sha1_digest_to_str(blob->id.sha1, buf, size);
822 size_t
823 got_object_blob_get_hdrlen(struct got_blob_object *blob)
825 return blob->hdrlen;
828 const uint8_t *
829 got_object_blob_get_read_buf(struct got_blob_object *blob)
831 return blob->read_buf;
834 const struct got_error *
835 got_object_blob_read_block(size_t *outlenp, struct got_blob_object *blob)
837 size_t n;
839 if (blob->flags & GOT_BLOB_F_COMPRESSED)
840 return got_inflate_read(&blob->zb, blob->f, outlenp);
842 n = fread(blob->read_buf, 1, blob->blocksize, blob->f);
843 if (n == 0 && ferror(blob->f))
844 return got_ferror(blob->f, GOT_ERR_IO);
845 *outlenp = n;
846 return NULL;