File tree 3 files changed +9027
-6174
lines changed
3 files changed +9027
-6174
lines changed Original file line number Diff line number Diff line change 13
13
14
14
const { toString } = Function . prototype ;
15
15
const functionNameMatch = / \s * f u n c t i o n (?: \s | \s * \/ \* [ ^ ( ? : * / ) ] + \* \/ \s * ) * ( [ ^ \s ( / ] + ) / ;
16
+ const maxFunctionSourceLength = 512 ;
16
17
function getFuncName ( aFunc ) {
17
18
if ( typeof aFunc !== 'function' ) {
18
19
return null ;
@@ -22,6 +23,12 @@ function getFuncName(aFunc) {
22
23
if ( typeof Function . prototype . name === 'undefined' && typeof aFunc . name === 'undefined' ) {
23
24
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
24
25
// 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
+ }
25
32
const match = toString . call ( aFunc ) . match ( functionNameMatch ) ;
26
33
if ( match ) {
27
34
[ name ] = match ;
You can’t perform that action at this time.
0 commit comments