left-pad
- Type
- Repo
- Scanned
- Nov 12, 2026
- Version
- 1.3.0
- Files read
- 10
This package provides a single helper function that pads the start of a string up to a target length. It cannot access files, the network, or system commands, and its main risk is freezing the Node.js process if an application passes unvalidated large lengths and non-string padding values into it.
Findings
-
LowInfinite loop on large lengths with empty-stringifying object padding
index.js:42
The function checks whether the padding argument ch is empty before converting it to a string, so passing a truthy object such as an empty array [] from unvalidated JSON turns ch into an empty string. When the remaining length falls in the 32-bit negative range (for example between 2147483648 and 4294967295), the signed bit-shift len >>= 1 shifts down to -1 and stays at -1 forever without growing the string or throwing an error, freezing the Node.js process at 100% CPU.
Fix: Convert ch to a string before checking whether it is empty, reject or cap unreasonably large len values, and use an unsigned right shift (len >>>= 1) so the loop always terminates.
