Improper Input Validation and Loop with Unreachable Exit Condition ('Infinite Loop') in cumulative-distribution-function
Description
cumulative-distribution-function is an open source npm library used which calculates statistical cumulative distribution function from data array of x values. In versions prior to 2.0.0 apps using this library on improper data may crash or go into an infinite-loop. In the case of a nodejs server-app using this library to act on invalid non-numeric data, the nodejs server may crash. This may affect other users of this server and/or require the server to be rebooted for proper operation. In the case of a browser app using this library to act on invalid non-numeric data, that browser may crash or lock up. A flaw enabling an infinite-loop was discovered in the code for evaluating the cumulative-distribution-function of input data. Although the documentation explains that numeric data is required, some users may confuse an array of strings like ["1","2","3","4","5"] for numeric data [1,2,3,4,5] when it is in fact string data. An infinite loop is possible when the cumulative-distribution-function is evaluated for a given point when the input data is string data rather than type number. This vulnerability enables an infinite-cpu-loop denial-of-service-attack on any app using npm:cumulative-distribution-function v1.0.3 or earlier if the attacker can supply malformed data to the library. The vulnerability could also manifest if a data source to be analyzed changes data type from Arrays of number (proper) to Arrays of string (invalid, but undetected by earlier version of the library). Users should upgrade to at least v2.0.0, or the latest version. Tests for several types of invalid data have been created, and version 2.0.0 has been tested to reject this invalid data by throwing a TypeError() instead of processing it. Developers using this library may wish to adjust their app's code slightly to better tolerate or handle this TypeError. Apps performing proper numeric data validation before sending data to this library should be mostly unaffected by this patch. The vulnerability can be mitigated in older versions by ensuring that only finite numeric data of type Array[number] or number is passed to cumulative-distribution-function and its f(x) function, respectively.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
cumulative-distribution-functionnpm | < 2.0.0 | 2.0.0 |
Affected products
2- DrPaulBrewer/cumulative-distribution-functionv5Range: < 2.0.0
Patches
Vulnerability mechanics
Root cause
"Missing input validation allows non-numeric data (e.g. strings) to enter the binary-search loop, which never finds a match and runs infinitely."
Attack vector
An attacker supplies an array of strings (e.g. `["1","2","3"]`) or other non-numeric values to the `cdf()` function instead of an array of finite numbers. Because the library prior to v2.0.0 does not validate the type of each element, the internal binary-search loop never finds a matching value and runs indefinitely, consuming 100% CPU. This can be delivered over HTTP if a Node.js server passes user-supplied JSON directly to the library, causing a denial-of-service that may crash the server or require a reboot. In a browser context, the same malformed input locks up the tab. The attack requires no authentication and only the ability to inject the malformed data into the library's input path. [CWE-20] [CWE-835]
What the fix does
The patch adds a validation loop at the top of `index.js` that checks every element of the input array: if `typeof(data[i])!=='number'` or `!isFinite(data[i])`, it throws a `TypeError` with a descriptive message. It also validates the `x` argument passed to the returned `f(x)` function, throwing if it is not a number. Additionally, calling `cdf()` with missing or empty data now throws a `TypeError` instead of silently returning a no-op function. These changes ensure that the binary-search loop inside `f(x)` only ever operates on valid numeric data, eliminating the infinite-loop condition. [patch_id=6635529]
Preconditions
- inputThe attacker must be able to supply an array of strings or other non-numeric values to the cumulative-distribution-function library's cdf() function.
- configThe application must not validate that input data is an array of finite numbers before passing it to the library.
Generated on Jun 20, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
6- github.com/advisories/GHSA-58qp-5328-v7mhghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-29486ghsaADVISORY
- github.com/DrPaulBrewer/cumulative-distribution-function/issues/7ghsax_refsource_MISCWEB
- github.com/DrPaulBrewer/cumulative-distribution-function/pull/8ghsax_refsource_MISCWEB
- github.com/DrPaulBrewer/cumulative-distribution-function/security/advisories/GHSA-58qp-5328-v7mhghsax_refsource_CONFIRMWEB
- www.npmjs.com/package/cumulative-distribution-functionghsax_refsource_MISCWEB
News mentions
0No linked articles in our index yet.