commit 0048f35afa41d388854a0aba3d335e433bb52445 from: Omar Polo date: Sun Jul 14 21:48:57 2024 UTC fix got_object_id initialization when parsing off a delta commit - b5f376b8e96fb99d8458d8046b950618cdc36c05 commit + 0048f35afa41d388854a0aba3d335e433bb52445 blob - 9d8c32aaad51cfe18240cfb06d39b674f6b6b6ac blob + d85bb9c97e68310aaa7e391da369828c9e43bbfb --- lib/pack.c +++ lib/pack.c @@ -1103,6 +1103,11 @@ const struct got_error * got_pack_parse_ref_delta(struct got_object_id *id, struct got_pack *pack, off_t delta_offset, int tslen) { + size_t digest_len = got_hash_digest_length(pack->algo); + + memset(id, 0, sizeof(*id)); + id->algo = pack->algo; + if (pack->map) { size_t mapoff; @@ -1115,13 +1120,13 @@ got_pack_parse_ref_delta(struct got_object_id *id, mapoff = delta_offset + tslen; if (mapoff + sizeof(*id) >= pack->filesize) return got_error(GOT_ERR_PACK_OFFSET); - memcpy(id, pack->map + mapoff, sizeof(*id)); + memcpy(id->hash, pack->map + mapoff, digest_len); } else { ssize_t n; - n = read(pack->fd, id, sizeof(*id)); + n = read(pack->fd, id->hash, digest_len); if (n < 0) return got_error_from_errno("read"); - if (n != sizeof(*id)) + if (n != digest_len) return got_error(GOT_ERR_BAD_PACKFILE); }