From: Taylor Blau <me@ttaylorr.com>
To: Phillip Wood <phillip.wood@dunelm.org.uk>
Cc: git@vger.kernel.org, Derrick Stolee <stolee@gmail.com>,
Phillip Wood <phillip.wood123@gmail.com>
Subject: Re: [PATCH 3/4] midx: avoid negative array index
Date: Tue, 20 May 2025 13:58:10 -0400 [thread overview]
Message-ID: <aCzCsv61ET4u7JOK@nand.local> (raw)
In-Reply-To: <688b0273604179b5bebe3748445158e09a7bf1a0.1747753388.git.phillip.wood@dunelm.org.uk>
On Tue, May 20, 2025 at 04:04:26PM +0100, Phillip Wood wrote:
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> nth_midxed_pack_int_id() returns the index of the pack file in the multi
> pack index's list of packfiles that the specified object. The index is
> returned as a uint32_t. Storing this in an int will make the index
> negative if the most significant bit is set. Fix this by using uint32_t
> as the rest of the code does. This is unlikely to be a practical problem
> as it requires the multipack index to reference 2^31 packfiles.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
> midx-write.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/midx-write.c b/midx-write.c
> index 2ee381e8fcd..38a458d7322 100644
> --- a/midx-write.c
> +++ b/midx-write.c
> @@ -1566,7 +1566,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
> _("Counting referenced objects"),
> m->num_objects);
> for (i = 0; i < m->num_objects; i++) {
> - int pack_int_id = nth_midxed_pack_int_id(m, i);
> + uint32_t pack_int_id = nth_midxed_pack_int_id(m, i);
> count[pack_int_id]++;
> display_progress(progress, i + 1);
> }
> @@ -1697,7 +1697,7 @@ static void fill_included_packs_batch(struct repository *r,
>
> total_size = 0;
> for (i = 0; total_size < batch_size && i < m->num_packs; i++) {
> - int pack_int_id = pack_info[i].pack_int_id;
> + uint32_t pack_int_id = pack_info[i].pack_int_id;
> struct packed_git *p = m->packs[pack_int_id];
> uint64_t expected_size;
>
> --
> 2.49.0.897.gfad3eb7d210
>
Thanks for catching these. I was going to comment on it as something I
noticed while reading the first patch, but I'm glad that you addressed
it here.
It looks like these two declarations date back to:
- 19575c7c8e (multi-pack-index: implement 'expire' subcommand, 2019-06-10)
- ce1e4a105b (midx: implement midx_repack(), 2019-06-10)
(both of which were merged via 4308d81d45 (Merge branch
'ds/midx-expire-repack', 2019-07-19)). But I think these have always had
the wrong type, since the pack_int_id field comes from commit fe1ed56f5e
(midx: sort and deduplicate objects from packfiles, 2018-07-12), where
it was first introduced as a uint32_t.
I actually think these all should size_t's since they're indexing into
an array, but that can be dealt with outside of this series, since this
is an obvious improvement.
Thanks,
Taylor
next prev parent reply other threads:[~2025-05-20 17:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 15:04 [PATCH 0/4] midx repack: fix overflow on 32 bit systems Phillip Wood
2025-05-20 15:04 ` [PATCH 1/4] midx repack: avoid integer " Phillip Wood
2025-05-20 17:54 ` Taylor Blau
2025-05-21 15:19 ` Phillip Wood
2025-05-23 0:34 ` Taylor Blau
2025-05-21 13:10 ` D. Ben Knoble
2025-05-21 15:01 ` Junio C Hamano
2025-05-21 15:20 ` Phillip Wood
2025-05-20 15:04 ` [PATCH 2/4] midx repack: avoid potential integer overflow on 64 " Phillip Wood
2025-05-20 17:59 ` Taylor Blau
2025-05-21 15:20 ` Phillip Wood
2025-05-20 15:04 ` [PATCH 3/4] midx: avoid negative array index Phillip Wood
2025-05-20 17:58 ` Taylor Blau [this message]
2025-05-20 15:04 ` [PATCH 4/4] midx docs: clarify tie breaking Phillip Wood
2025-05-20 18:07 ` Taylor Blau
2025-05-21 15:20 ` Phillip Wood
2025-05-21 13:14 ` D. Ben Knoble
2025-05-22 15:55 ` [PATCH v2 0/4] midx repack: fix overflow on 32 bit systems Phillip Wood
2025-05-22 15:55 ` [PATCH v2 1/4] midx repack: avoid integer " Phillip Wood
2025-05-22 15:55 ` [PATCH v2 2/4] midx repack: avoid potential integer overflow on 64 " Phillip Wood
2025-05-22 15:55 ` [PATCH v2 3/4] midx: avoid negative array index Phillip Wood
2025-05-22 15:55 ` [PATCH v2 4/4] midx docs: clarify tie breaking Phillip Wood
2025-05-23 0:36 ` [PATCH v2 0/4] midx repack: fix overflow on 32 bit systems Taylor Blau
2025-05-27 8:26 ` Phillip Wood
2025-05-27 15:42 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aCzCsv61ET4u7JOK@nand.local \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood123@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=stolee@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.