Last modified: 2014-09-24 22:46:28 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 T73061, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 71061 - Count of arrays from LuaSandbox incorrect under HHVM
Count of arrays from LuaSandbox incorrect under HHVM
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
Scribunto (Other open bugs)
unspecified
All All
: High major (vote)
: ---
Assigned To: Tim Starling
https://test2.wikipedia.org/wiki/Lua_...
: hhvm
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-09-19 18:38 UTC by Mormegil
Modified: 2014-09-24 22:46 UTC (History)
5 users (show)

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


Attachments
Python script based on Jackmcbarn's test case (885 bytes, text/plain)
2014-09-21 22:54 UTC, Ori Livneh
Details

Description Mormegil 2014-09-19 18:38:12 UTC
When trying HHVM, I noticed pages using [[cs:Module:Diagram]] on cswiki displayed script error. After testing a little bit, it seems mw.ustring.gmatch sometimes terminates its search prematurely (and returns a shorter list than it should).

On the linked test2 page, the diagram (taken from cs) sometimes render correctly, sometimes renders only partially (some data is ignored), sometimes results in Script error ("no slices found - can't draw pie chart"), as _no_ data at all is found by the mw.ustring.gmatch( slicesStr or '', "%b()" ) input parser.
Comment 1 Jackmcbarn 2014-09-20 04:10:01 UTC
I've created a reduced version of the test that reveals the bug, at https://test2.wikipedia.org/wiki/Module:71061 and https://test2.wikipedia.org/wiki/Module:71061/doc .
Comment 2 Jackmcbarn 2014-09-20 04:46:38 UTC
I've tracked this down to a bug in LuaSandbox. When an array from LuaSandbox is passed to count() under HHVM, count() returns 4294967295 instead of the array's actual size.
Comment 3 Ori Livneh 2014-09-21 07:19:31 UTC
I think it has to do with ArrayData::m_size being a uint32_t but getting initialized to -1 in hphp/runtime/base/proxy-array.cpp:67.
Comment 4 Ori Livneh 2014-09-21 22:52:32 UTC
(In reply to Jackmcbarn from comment #2)
> I've tracked this down to a bug in LuaSandbox. When an array from LuaSandbox
> is passed to count() under HHVM, count() returns 4294967295 instead of the
> array's actual size.

With Jackmcbarn's test script, this manifests in the size of $capt at the top of Scribunto_LuaUstringLibrary::ustringGmatchCallback sometime ballooning to 4294967295.
Comment 5 Ori Livneh 2014-09-21 22:54:18 UTC
Created attachment 16534 [details]
Python script based on Jackmcbarn's test case

This script will make three identical requests to the Scribunto API. This output is typical on osmium:

Request #1 (duration: 2.02s):
PHP = "(Č)"
done

Request #2 (duration: 111.30s):
done

Request #3 (duration: 0.34s):
PHP = "(Č)"
done


Notice that the first and third requests are fine, and that the second requests takes unusually longer to process.
Comment 6 Tim Starling 2014-09-22 00:20:13 UTC
I am working on a fix now. The problem is apparently CodeGenerator::cgCountArray(). Probably everything that uses ArrayData::offsetofSize() is broken.

Reduced test case:

<?php

$lua = 'return test.test({0})';

function test( $x ) {
	return array(count( $x ));
}

$sb = new LuaSandbox;
$sb->registerLibrary( 'test', array('test'=>'test'));
$ret = $sb->loadString( $lua )->call();
print "$ret[0]\n";
$sb = null;
Comment 7 Tim Starling 2014-09-22 05:11:09 UTC
https://github.com/facebook/hhvm/pull/3811
Comment 8 Ori Livneh 2014-09-24 22:46:28 UTC
(In reply to Tim Starling from comment #7)
> https://github.com/facebook/hhvm/pull/3811

Nice; thanks.

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


Navigation
Links