From: Elijah Newren Date: Sun, 19 Apr 2026 00:26:08 GMT Subject: Re: [PATCH 7/8] pack-bitmap: reject pseudo-merge "sampleRate" of 0 Message-ID: In-Reply-To: <1b0f7295c21bf6240bef975e5f3fb9da685f29d3.1776124589.git.me@ttaylorr.com> On Mon, Apr 13, 2026 at 4:56 PM Taylor Blau wrote: > > The "bitmapPseudoMerge.*.sampleRate" configuration controls what > fraction of unstable commits are included in each pseudo-merge group. > The config validation accepts values in the range `[0, 1]`, but a value > of exactly 0 causes a division by zero in `select_pseudo_merges_1()`: > > if (j % (uint32_t)(1.0 / group->sample_rate)) > > When `sample_rate` is 0, `1.0 / 0.0` produces `+inf`, and casting > infinity to `uint32_t` is undefined behavior in C. On most platforms > this yields 0, making the subsequent modulo operation (`j % 0`) a > fatal arithmetic trap. > > This path was not previously reachable because an earlier bug caused > all pseudo-merge candidates to be classified as "stable" (where the > sampling rate is not used), regardless of their actual commit date. Now > that the date classification is fixed, the unstable path is exercised > and the division by zero can fire. > > Fix this by changing the validation to require a strict lower bound and > thus reject 0. > > Signed-off-by: Taylor Blau > --- > pseudo-merge.c | 4 ++-- > t/t5333-pseudo-merge-bitmaps.sh | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/pseudo-merge.c b/pseudo-merge.c > index d79e5fb649a..75bed043602 100644 > --- a/pseudo-merge.c > +++ b/pseudo-merge.c > @@ -169,8 +169,8 @@ static int pseudo_merge_config(const char *var, const char *value, > } > } else if (!strcmp(key, "samplerate")) { > group->sample_rate = git_config_double(var, value, ctx->kvi); > - if (!(0 <= group->sample_rate && group->sample_rate <= 1)) { > - warning(_("%s must be between 0 and 1, using default"), var); > + if (!(0 < group->sample_rate && group->sample_rate <= 1)) { > + warning(_("%s must be between 0 (exclusive) and 1, using default"), var); The documentation for `bitmapPseudoMerge..sampleRate` in Documentation/config/bitmap-pseudo-merge.adoc still claims that 0 is allowed; should that be fixed as part of this patch? Also: ``` $ git grep -B 4 -i samplerate.*= Documentation/gitpacking.adoc-[bitmapPseudoMerge "all"] Documentation/gitpacking.adoc- pattern = "refs/" Documentation/gitpacking.adoc- threshold = now Documentation/gitpacking.adoc- stableThreshold = never Documentation/gitpacking.adoc: sampleRate = 100 -- Documentation/gitpacking.adoc-[bitmapPseudoMerge "all"] Documentation/gitpacking.adoc- pattern = "refs/virtual/([0-9]+)/(heads|tags)/" Documentation/gitpacking.adoc- threshold = now Documentation/gitpacking.adoc- stableThreshold = never Documentation/gitpacking.adoc: sampleRate = 100 ``` Should those sampleRates be fixed?