From df55da00262a7a6b7f885e3fc66559767761cae5 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 26 Mar 2026 23:45:07 -0700 Subject: Fix Phased-Update-Percentage probability mistake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously a package with Phased-Update-Percentage: n would be updated with probability (n + 1)/101 instead of n/100. For example, a package with Phased-Update-Percentage: 0 could still be updated even though it shouldn’t, and a package with Phased-Update-Percentage: 1 would be installed almost twice as much as it should be. Correct the erroneous math. Note that libstdc++ implements std::uniform_int_distribution in such a way that for a given seed, changing dist(0, 100) to dist(0, 99) has the effect of decreasing each sample by 0 or 1; therefore, this patch will not randomly trigger extra phased updates that had previously been excluded. Fixes: c5bc86d45e003905ef411146e66b414d26fb1ff8 Signed-off-by: Anders Kaseorg --- apt-pkg/depcache.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg/depcache.cc') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 2a9ef50d2..777fa0c80 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -2591,9 +2591,9 @@ static bool IsIgnoredPhasedUpdate(std::string machineID, pkgCache::VerIterator c std::string seedStr = std::string(Ver.SourcePkgName()) + "-" + Ver.SourceVerStr() + "-" + machineID; std::seed_seq seed(seedStr.begin(), seedStr.end()); std::minstd_rand rand(seed); - std::uniform_int_distribution dist(0, 100); + std::uniform_int_distribution dist(0, 99); - return dist(rand) > Ver.PhasedUpdatePercentage(); + return dist(rand) >= Ver.PhasedUpdatePercentage(); } bool pkgDepCache::PhasingApplied(pkgCache::PkgIterator Pkg) const -- cgit v1.2.3-70-g09d2