Page MenuHomePhabricator

JS crash in mw.user.generateRandomSessionId()
Closed, ResolvedPublic

Description

I caught the error stack listed below.

I have no idea why and when and how to reproduce, but the reason is rather obvious.

Error: Cannot convert 'rnds' to object

Caused in rMW/resources/src/mediawiki.user.js Lines 52...63

  • var rnds has been declared.
  • The true branch of if will initialize rnds = new Uint16Array( 5 );
  • The else branch does not initialize rnds.
  • It starts assigning Array elements: rnds[ i ] =

Blaming: rMW29c803227f0daea2664c16966596c012b303cec2

Parts of stack trace following:

Error thrown at line 118, column 20690 in <anonymous function: generateRandomSessionId>()
rnds[i]=Math.floor(Math.random()*0x10000)
called from line 296, column 1198 in getToken()
token=mw.user.generateRandomSessionId(); called from line 296, column 1191 in <anonymous function>
userToken=getToken(); called from line 296, column 391 in <anonymous function>
(function($,mw){var isMobile=mw.config.get('skin')==='minerva',userToken,trackedFeatures={},userSampling=10;function getToken(){var keyName='wmE-GeoFeaturesUser',token=mw.storage.session.get(keyName),parts=token&&token.split('|'),now=Date.now(),cut=now-(10*60*1000);if(parts&&parts[1]>=cut){return parts[0];}token=mw.user.generateRandomSessionId();mw.storage.session.set(keyName,token+'|'+now);return token;}userToken=getToken();function oneIn(sessionId,populationSize){var parsed=parseInt(sessionId.slice(0,13),16);return parsed%populationSize===0;}function randomOneIn(populationSize){var rand=mw.user. called from line 95, column 165 in <anonymous function: runScript>()
called from line 96, column 527 in execute(module)
execute(m); called from line 94, column 1624 in <anonymous function: markModuleReady>()
handlePending(module); called from line 95, column 234 in <anonymous function:
runScript>() 
markModuleReady(); called from line 96, column 527 in execute(module)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 31 2018, 7:34 PM

@PerfektesChaos Thanks for reporting. Which browser did you find this issue in?

An older one, I am afraid.

Krinkle triaged this task as Unbreak Now! priority.Aug 31 2018, 7:41 PM
Krinkle added a project: MediaWiki-General.
Krinkle added a subscriber: Nuria.

Follows-up T201124 and 29c803227f0daea. The unit test should have caught this, but I see now that the unit test for testing the "Math.random fallback" is actually failing to disable the Crypto API, as such, it is actually testing the modern branch twice, instead of testing both modern and falback.

Restricted Application added subscribers: Liuxinyu970226, TerraCodes. · View Herald TranscriptAug 31 2018, 7:41 PM

An older one, I am afraid.

Can you be more specific please? Name and numbers :)

Nuria added a comment.Aug 31 2018, 7:43 PM

Fix on the way. One Sec.

Change 456678 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] mediawiki.user: Update Crypto-fallback test to actually test the fallback

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

Krinkle reassigned this task from Jdlrobson to Nuria.Aug 31 2018, 7:47 PM
Krinkle added a subscriber: Jdlrobson.

Change 456682 had a related patch set uploaded (by Nuria; owner: Nuria):
[mediawiki/core@master] Proper initialization of array on generateRandomSessionId

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

Change 456678 abandoned by Krinkle:
mediawiki.user: Update Crypto-fallback test to actually test the fallback

Reason:
Squashed into I8feecddf0878

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

Krinkle claimed this task.Sep 1 2018, 12:24 AM
Krinkle edited projects, added Performance-Team; removed Performance-Team (Radar).

(continuing assignment, I'll review and deploy this.)

Change 456776 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@wmf/1.32.0-wmf.19] mediawiki.user: Fix missing array initialization in generateRandomSessionId

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

Change 456682 merged by jenkins-bot:
[mediawiki/core@master] mediawiki.user: Fix missing array initialization in generateRandomSessionId

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

Change 456776 merged by jenkins-bot:
[mediawiki/core@wmf/1.32.0-wmf.19] mediawiki.user: Fix missing array initialization in generateRandomSessionId

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

Mentioned in SAL (#wikimedia-operations) [2018-09-01T01:50:05Z] <krinkle@deploy1001> Synchronized php-1.32.0-wmf.19/resources/src/mediawiki.user.js: I8feecddf0878 - T203275 (duration: 00m 49s)

Krinkle closed this task as Resolved.Sep 3 2018, 8:08 PM