Skip to content

Commit f934b22

Browse files
authored
Merge pull request from GHSA-4q6p-r6v2-jvc5
1 parent 1436af2 commit f934b22

File tree

3 files changed

+9027
-6174
lines changed

3 files changed

+9027
-6174
lines changed

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
const { toString } = Function.prototype;
1515
const functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*/)]+\*\/\s*)*([^\s(/]+)/;
16+
const maxFunctionSourceLength = 512;
1617
function getFuncName(aFunc) {
1718
if (typeof aFunc !== 'function') {
1819
return null;
@@ -22,6 +23,12 @@ function getFuncName(aFunc) {
2223
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
2324
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
2425
// eslint-disable-next-line prefer-reflect
26+
const functionSource = toString.call(aFunc);
27+
// To avoid unconstrained resource consumption due to pathalogically large function names,
28+
// we limit the available return value to be less than 512 characters.
29+
if (functionSource.indexOf('(') > maxFunctionSourceLength) {
30+
return name;
31+
}
2532
const match = toString.call(aFunc).match(functionNameMatch);
2633
if (match) {
2734
[ name ] = match;

0 commit comments

Comments
 (0)