Last modified: 2014-04-02 19:50:44 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T64291, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 62291 - The seed for math.random() should be reset before #invoke
The seed for math.random() should be reset before #invoke
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Scribunto (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Brad Jorsch
: easy
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-03-06 00:03 UTC by orlodrim
Modified: 2014-04-02 19:50 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description orlodrim 2014-03-06 00:03:21 UTC
Since the seed is not reset, math.random() can be used to propagate a global state between indenpendent module invocations, which should be avoided.

Example: http://fr.wikipedia.org/w/index.php?title=Module:Sandbox&oldid=101826839
Comment 1 Brad Jorsch 2014-03-10 17:32:58 UTC
Since math.random is supposed to be an interface to the C rand() function,[1] and that function is explicitly defined as being seeded with 1 if srand (math.randomseed) hasn't been called,[2] I'd suggest fixing this by calling math.randomseed( 1 ) at the top of mw.executeFunction() (in engines/LuaCommon/lualib/mw.lua).

If no one objects in a reasonable period of time (and no one beats me to it), I'll submit a Gerrit change to do this at some point in the not-too-distant future.

 [1]: http://www.lua.org/manual/5.1/manual.html#pdf-math.random
 [2]: http://manpages.debian.net/cgi-bin/man.cgi?query=rand&sektion=3&format=html
Comment 2 orlodrim 2014-03-11 23:51:41 UTC
After thinking about it again, this probably requires some extra care in case of nested modules invocations. Otherwise, the random generator might be unexpectedly reset when frame:expandTemplate() is called, for instance.
Comment 3 Brad Jorsch 2014-04-01 17:47:05 UTC
(In reply to orlodrim from comment #2)
> After thinking about it again, this probably requires some extra care in
> case of nested modules invocations. Otherwise, the random generator might be
> unexpectedly reset when frame:expandTemplate() is called, for instance.

Good catch!
Comment 4 Gerrit Notification Bot 2014-04-01 17:47:33 UTC
Change 122862 had a related patch set uploaded by Anomie:
Prevent passing information between #invokes using math.random

https://gerrit.wikimedia.org/r/122862
Comment 5 Gerrit Notification Bot 2014-04-02 19:28:25 UTC
Change 122862 merged by jenkins-bot:
Prevent passing information between #invokes using math.random

https://gerrit.wikimedia.org/r/122862

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links