commit 2b02ed351e68831d6bd5bc93f18d563679084a51 from: Stefan Sperling via: Thomas Adam date: Tue Jul 22 08:17:38 2025 UTC reset file position when reusing per-repository temporary files When reusing a temporary file, do not forget to reset its file position to zero. Otherwise, opening multiple raw objects in a row can fail during delta application with an unexpected file size reported by stat(2). Problem reported by Aaron Lin Problem reproduced and fix verified with a repository provided by Aaron. I have unsuccessfully tried to write a regression test for this. ok op@ commit - 04b841e4697edff06c9f91aacea329b970b76f59 commit + 2b02ed351e68831d6bd5bc93f18d563679084a51 blob - 25d0ffb75d7e8448d934b6c293c32e6502583ca6 blob + 287ba8003842bf4e78f4beda762dda10d88e453b --- lib/repository.c +++ lib/repository.c @@ -395,6 +395,8 @@ got_repo_temp_fds_get(int *fd, int *idx, struct got_re if (repo->tempfiles[i] != -1) { if (ftruncate(repo->tempfiles[i], 0L) == -1) return got_error_from_errno("ftruncate"); + if (lseek(repo->tempfiles[i], 0L, SEEK_SET) == -1) + return got_error_from_errno("lseek"); *fd = repo->tempfiles[i]; *idx = i; repo->tempfile_use_mask |= (1 << i);