summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Kaseorg <andersk@mit.edu>2026-03-26 23:45:07 -0700
committerJulian Andres Klode <jak@debian.org>2026-04-07 09:34:15 +0000
commitdf55da00262a7a6b7f885e3fc66559767761cae5 (patch)
tree4065ff1f0a7a4848822803e903565dec111bf732
parent6cc5779d18baf520278952aed504b9d9b168a4bd (diff)
Fix Phased-Update-Percentage probability mistake
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 <andersk@mit.edu>
-rw-r--r--apt-pkg/depcache.cc4
-rw-r--r--apt-pkg/policy.cc4
2 files changed, 4 insertions, 4 deletions
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<unsigned int> dist(0, 100);
+ std::uniform_int_distribution<unsigned int> dist(0, 99);
- return dist(rand) > Ver.PhasedUpdatePercentage();
+ return dist(rand) >= Ver.PhasedUpdatePercentage();
}
bool pkgDepCache::PhasingApplied(pkgCache::PkgIterator Pkg) const
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index ab21cd039..7d11ba898 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -314,9 +314,9 @@ static inline bool ExcludePhased(std::string machineID, pkgCache::VerIterator co
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<unsigned int> dist(0, 100);
+ std::uniform_int_distribution<unsigned int> dist(0, 99);
- return dist(rand) > Ver.PhasedUpdatePercentage();
+ return dist(rand) >= Ver.PhasedUpdatePercentage();
}
APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver, bool ConsiderFiles)
{