fix: avoid integer overflow in stats/base/dists/hypergeometric - #14972
Draft
Planeshifter wants to merge 1 commit into
Draft
fix: avoid integer overflow in stats/base/dists/hypergeometric#14972Planeshifter wants to merge 1 commit into
stats/base/dists/hypergeometric#14972Planeshifter wants to merge 1 commit into
Conversation
Propagates fix from 493166d ("fix: perform support checks before integer narrowing") to sibling packages with the same int32 support-bound arithmetic. The expression `n+K-N` in the C implementations of `pmf`, `logpmf`, and `quantile` was evaluated in int32 arithmetic before conversion to double, overflowing (undefined behavior) for in-domain inputs where `n+K` exceeds the int32 range. Mirror the fixed `cdf` implementation by computing support bounds with double intermediates; in `quantile`, additionally convert the loop variable and bounds to doubles. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015CyugoNH33WVr8ghD2PhZr
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
developbetween 2026-09-03 and 2026-09-04 to sibling packages.Propagates the
int32_toverflow fix from 493166d (PR #14933) into the three remaininghypergeometricpackages that share the defect:pmf,logpmf, andquantileeach computen+K-Nin 32-bit integer arithmetic prior to conversion todouble, overflowing for in-domain inputs wheren+K > 2^31-1(e.g.N = K = n = 2e9). Applies the same idiom as the fixedcdf:dn/dK/dNdouble locals feedingstdlib_base_max( 0.0, dn+dK-dN ), withquantileadditionally convertinglower/upper/xand its search loop to double (x += 1.0) and collapsing its signature to the single-line form used across every otherquantile/src/main.cinstats/base/dists.Source: 493166d ("fix: perform support checks before integer narrowing")
@stdlib/stats/base/dists/hypergeometric/pmf@stdlib/stats/base/dists/hypergeometric/logpmf@stdlib/stats/base/dists/hypergeometric/quantileRelated Issues
This pull request has no related issues.
Questions
No.
Other
Validation performed before applying the propagation:
developin the last 24 hours were screened for generalizable fixes; five candidate patterns were extracted, and pattern searches were run across the respective sibling namespaces.int32_toverflow ofn+K-Nis reachable for guard-passing inputs) and confirmed the double-arithmetic rewrite is bit-exact for all non-overflowing inputs.cdfimplementation's idiom (declaration ordering,dn/dK/dNlocals, single-line signature convention).{PositiveNumber}→{NonNegativeNumber}lambda, source 0fdb09d) — all rejected because zero-acceptance at those sites is incidental (no degenerate-case branch) or diverges between JS and native paths; one site (wald/pdf/lib/native.js) is already fixed by open PR fix: apply follow-up fixes from automated review of recent commits #14969.gcc -std=c99 -Wall -Wextra -fsyntax-only.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written by Claude Code as part of an automated fix-propagation routine; each target site was verified by two independent validation passes plus adaptation and style-consistency passes before the patches were applied.
@stdlib-js/reviewers
🤖 Generated with Claude Code
https://claude.ai/code/session_015CyugoNH33WVr8ghD2PhZr
Generated by Claude Code