commit bdb6cb9b8b2633c831f532e05cb1780710cde9a8 from: Stefan Sperling date: Tue Mar 07 16:36:45 2023 UTC fix gotd sometimes reading reused deltas from wrong pack file The reuse-pack is pinned but may change its cache slot while objects are being deltified. Refresh the pointer to the pinned reuse-pack before writing out the pack file, ensuring that reused deltas will in fact be read from the reuse-pack and not some other pack. Otherwise gotd may send a broken pack file, or hit an ERR_RANGE condition if the pack file which now occupies the pinned-pack's old cache slot is shorter. Which can trigger attempts to read beyond end-of-file which show up in the logs like this: gotd[37311]: repo_read /var/git/got.git: sending packfile: value out of range gotd[43877]: uid 1002: value out of range gotd[43877]: uid 1002: disconnecting commit - 15aed0533476711f5f9e6c64c1e220f6e960e7fa commit + bdb6cb9b8b2633c831f532e05cb1780710cde9a8 blob - a467a2aec8f4b84bb79456886304f79f16160ad4 blob + ac4cf855434fedcf1669f57482225399f9486b03 --- lib/pack_create.c +++ lib/pack_create.c @@ -1933,6 +1933,9 @@ got_pack_create(uint8_t *packsha1, int packfd, FILE *d goto done; } + /* Pinned pack may have moved to different cache slot. */ + reuse_pack = got_repo_get_pinned_pack(repo); + err = genpack(packsha1, packfd, reuse_pack, delta_cache, deltify.meta, deltify.nmeta, reuse.meta, reuse.nmeta, ncolored, nfound, ntrees, nours, repo, force_refdelta, progress_cb, progress_arg, rl,