You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I stumbled upon an issue where calling seed() causes an (almost) infinite recursive loop:
seed() is called without arguments, in which case it uses a local entropy. This entropy is generated (amongst others) from all globally defined objects.
seed() is called via a getter on an object which is globally defined (obj.random in the example).
hence, when creating the local entropy, seed calls the obj.random getter which calls seed again -> infinite loop
node.js example code:
varseed=require('seed-random');varcount=0;// create an objectvarobj={};// expose the object globallyglobal.obj=obj;Object.defineProperty(obj,'random',{get: function(){console.log('obj.random getter');count++;// call seed inside a getter of the globally defined objectreturnseed();},configurable: true,enumerable: true});// call the getter... will cause an (almost) infinite loopvara=obj.random();console.log('a',a);console.log('number of recursive loops over obj.random (should be 1):',count);// outputs for example count = 1425
Some ideas for a solution:
Ignore properties which are getters when creating local entropy
Output an informative warning when this loop happens (check whether seed is called whilst it's being executed)
Throw an error when seed is called whilst it is being executed, and when generating local entropy, catch this error and silently ignore it.
The text was updated successfully, but these errors were encountered:
I stumbled upon an issue where calling
seed()
causes an (almost) infinite recursive loop:seed()
is called without arguments, in which case it uses a local entropy. This entropy is generated (amongst others) from all globally defined objects.seed()
is called via a getter on an object which is globally defined (obj.random
in the example).obj.random
getter which calls seed again -> infinite loopnode.js example code:
Some ideas for a solution:
The text was updated successfully, but these errors were encountered: