commit ab62f2123a6a5e453ab9645daf04cd1f2bd8442d from: Omar Polo date: Fri Jul 12 12:59:03 2024 UTC add an algo field to struct got_packidx ok tobhe@, stsp@ commit - c3434cef3dd7dbd62000d244d716b997f98226a5 commit + ab62f2123a6a5e453ab9645daf04cd1f2bd8442d blob - 1b9a3c7d50834fc34fcac7ff7919ea96d024bf44 blob + a31098e14ec3916c567d922a117d7d74baf597a8 --- lib/got_lib_pack.h +++ lib/got_lib_pack.h @@ -122,6 +122,7 @@ struct got_pack_large_offset_index { struct got_packidx { char *path_packidx; /* actual on-disk path */ int fd; + enum got_hash_algorithm algo; uint8_t *map; size_t len; size_t nlargeobj; @@ -160,7 +161,7 @@ struct got_packfile_obj_hdr { const struct got_error *got_packidx_init_hdr(struct got_packidx *, int, off_t); const struct got_error *got_packidx_open(struct got_packidx **, - int, const char *, int); + int, const char *, int, enum got_hash_algorithm); const struct got_error *got_packidx_close(struct got_packidx *); const struct got_error *got_packidx_get_packfile_path(char **, const char *); off_t got_packidx_get_object_offset(struct got_packidx *, int idx); blob - a17be0408a103339d10ae1a1e9736deb19fb0b74 blob + 9365381c6d173fbb3fedfb6b7d428db95f6e93f5 --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -513,6 +513,7 @@ struct got_imsg_index_pack_progress { struct got_imsg_packidx { size_t len; off_t packfile_size; + int algo; /* Additionally, a file desciptor is passed via imsg. */ }; blob - 84302f45b8db014cc23483d23a273c03f7fa077c blob + 5aabc43dd66acd9a5cb6ffe80627cc59ca257fbf --- lib/pack.c +++ lib/pack.c @@ -75,7 +75,6 @@ const struct got_error * got_packidx_init_hdr(struct got_packidx *p, int verify, off_t packfile_size) { const struct got_error *err = NULL; - enum got_hash_algorithm algo = GOT_HASH_SHA1; struct got_packidx_v2_hdr *h; struct got_hash ctx; uint8_t hash[GOT_HASH_DIGEST_MAXLEN]; @@ -83,7 +82,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify ssize_t n; int i; - got_hash_init(&ctx, algo); + got_hash_init(&ctx, p->algo); h = &p->hdr; offset = 0; @@ -183,7 +182,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify remain -= len_fanout; nobj = be32toh(h->fanout_table[0xff]); - len_ids = nobj * sizeof(*h->sorted_ids); + len_ids = nobj * got_hash_digest_length(p->algo); if (len_ids <= nobj || len_ids > remain) { err = got_error(GOT_ERR_BAD_PACKIDX); goto done; @@ -327,7 +326,7 @@ checksum: } if (verify) { got_hash_update(&ctx, h->trailer->packfile_sha1, - SHA1_DIGEST_LENGTH); + got_hash_digest_length(p->algo)); got_hash_final(&ctx, hash); if (got_hash_cmp(ctx.algo, hash, h->trailer->packidx_sha1) != 0) err = got_error(GOT_ERR_PACKIDX_CSUM); @@ -338,7 +337,8 @@ done: const struct got_error * got_packidx_open(struct got_packidx **packidx, - int dir_fd, const char *relpath, int verify) + int dir_fd, const char *relpath, int verify, + enum got_hash_algorithm algo) { const struct got_error *err = NULL; struct got_packidx *p = NULL; @@ -371,6 +371,8 @@ got_packidx_open(struct got_packidx **packidx, goto done; } + p->algo = algo; + p->fd = openat(dir_fd, relpath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC); if (p->fd == -1) { err = got_error_from_errno2("openat", relpath); blob - 8aa0ad08ca44ef4b71ccf60df2cf2b962c13da78 blob + 5d128736fd8cc8b24a9e2f8fd6edd0d243752fcc --- lib/pack_index.c +++ lib/pack_index.c @@ -211,7 +211,7 @@ read_packed_object(struct got_pack *pack, struct got_i } if (err) break; - got_hash_init(&ctx, GOT_HASH_SHA1); + got_hash_init(&ctx, pack->algo); err = got_object_type_label(&obj_label, obj->type); if (err) { free(data); @@ -414,7 +414,7 @@ resolve_deltified_object(struct got_pack *pack, struct goto done; } headerlen = strlen(header) + 1; - got_hash_init(&ctx, GOT_HASH_SHA1); + got_hash_init(&ctx, pack->algo); got_hash_update(&ctx, header, headerlen); if (max_size > GOT_DELTA_RESULT_SIZE_CACHED_MAX) { err = read_file_digest(&ctx, tmpfile, len); @@ -644,7 +644,7 @@ got_pack_index(struct got_pack *pack, int idxfd, FILE "bad packfile with zero objects"); /* We compute the SHA1 of pack file contents and verify later on. */ - got_hash_init(&ctx, GOT_HASH_SHA1); + got_hash_init(&ctx, pack->algo); got_hash_update(&ctx, &hdr, sizeof(hdr)); /* blob - 1edd0153662b01a8fd962579a4b5a7c5af42df69 blob + 9fc1dd22c6d4e2c1868cd493424a0d5b4fe5ed5a --- lib/privsep.c +++ lib/privsep.c @@ -1960,6 +1960,7 @@ got_privsep_init_pack_child(struct imsgbuf *ibuf, stru ipackidx.len = packidx->len; ipackidx.packfile_size = pack->filesize; + ipackidx.algo = packidx->algo; fd = dup(packidx->fd); if (fd == -1) return got_error_from_errno("dup"); blob - 7323331c86c9085cb6ec9fdad463a7ff32f92518 blob + 47e4642c06e4806292166b184a34bedafab3eb6c --- lib/repository.c +++ lib/repository.c @@ -1384,7 +1384,7 @@ got_repo_search_packidx(struct got_packidx **packidx, continue; /* already searched */ err = got_packidx_open(packidx, got_repo_get_fd(repo), - path_packidx, 0); + path_packidx, 0, repo->algo); if (err) goto done; @@ -1486,7 +1486,7 @@ got_repo_get_packidx(struct got_packidx **packidx, con /* No luck. Search the filesystem. */ err = got_packidx_open(packidx, got_repo_get_fd(repo), - path_packidx, 0); + path_packidx, 0, repo->algo); if (err) return err; @@ -1817,7 +1817,7 @@ retry: path_packidx = pe->path; err = got_packidx_open(&packidx, got_repo_get_fd(repo), - path_packidx, 0); + path_packidx, 0, repo->algo); if (err) break; @@ -2563,7 +2563,7 @@ got_repo_get_packfile_info(int *npackfiles, int *nobje } err = got_packidx_open(&packidx, got_repo_get_fd(repo), - path_packidx, 0); + path_packidx, 0, repo->algo); free(path_packidx); if (err) goto done; blob - b0168b3397ef9e155f6ca23c6057126006b3f1f6 blob + da0b3b49fa523700d29c8be5ec7542ae6ecc9c4e --- lib/repository_admin.c +++ lib/repository_admin.c @@ -548,7 +548,8 @@ got_repo_list_pack(FILE *packfile, struct got_object_i goto done; } - err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1); + err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1, + repo->algo); if (err) goto done; blob - aec894fa8b4604174f7faf23446d66e16ac0d570 blob + b4ec204772c2f95248eaebb7f4c5d724d535c17b --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -1146,6 +1146,7 @@ receive_packidx(struct got_packidx **packidx, struct i } memcpy(&ipackidx, imsg.data, sizeof(ipackidx)); + p->algo = ipackidx.algo; p->fd = imsg_get_fd(&imsg); p->len = ipackidx.len; if (p->fd == -1) {