Patch from Igor: Hi, Norris!
Patch from Igor:
Hi, Norris!

I have found few problems with NativeArraj.java.

1. jsSet_length requires that the new length value should be an instance of Number. But according to Ecma 15.4.5.1, item 12-13, an error should be thrown only if ToUint32(length_value) != ToNumber(length_value). Here is a simple test that demonstrates it:

Array(5).length = new Number(1)

It currenly throws an exception.

2. jsSet_length when executing the code marked with "// assume that the representation is sparse" effectively removes all properties with values less then the current length when String is used to represent its value. Note that simply changing lines "if (d == d && d < length) delete(id);" to "if (d == d && d >= longVal) delete(id);" is not good because it would remove properties like "4.5" or "007", the full array index check has to be used instead.

Here is a test case that catches the problem:

var BIG_INDEX = 4294967290;
var a = Array(BIG_INDEX);
a[BIG_INDEX - 1] = 'a';
a[BIG_INDEX - 10000] = 'b';
a[BIG_INDEX - 0.5] = 'c';

a.length = BIG_INDEX - 5000;
var s = '';
for (var i in a) s += a[i];

print('s="'+s+'"');

this should print s='cb' (or 'bc': EcmaScript does not fix the order), but currently it gives s=''.

3. There are race conditions in jsSet_length and getIds.
The first contains:
                    if (hasElem(this, i))
                        ScriptRuntime.delete(this, new Long(i));
which would lead to call to delete in the Array prototype if 2 threads would invoke this code. Simply calling ScriptableObject.delete without any checks for existence is enough here.

getIds assumes that the count of present elements in the dense array does not change, which is not true when another thread deletes elements from dense.

The attached patch fixes these issues.

Regards, Igor

qhanam/rhino,tejassaoji/RhinoCoarseTainting,ashwinrayaprolu1984/rhino,lv7777/egit_test,tuchida/rhino,Distrotech/rhino,Angelfirenze/rhino,ashwinrayaprolu1984/rhino,swannodette/rhino,tejassaoji/RhinoCoarseTainting,AlexTrotsenko/rhino,Pilarbrist/rhino,Pilarbrist/rhino,tejassaoji/RhinoCoarseTainting,sam/htmlunit-rhino-fork,sam/htmlunit-rhino-fork,swannodette/rhino,lv7777/egit_test,ashwinrayaprolu1984/rhino,sainaen/rhino,lv7777/egit_test,tntim96/htmlunit-rhino-fork,ashwinrayaprolu1984/rhino,sainaen/rhino,tuchida/rhino,tntim96/rhino-apigee,tejassaoji/RhinoCoarseTainting,ashwinrayaprolu1984/rhino,ashwinrayaprolu1984/rhino,Pilarbrist/rhino,Angelfirenze/rhino,Distrotech/rhino,AlexTrotsenko/rhino,tntim96/rhino-apigee,tejassaoji/RhinoCoarseTainting,ashwinrayaprolu1984/rhino,lv7777/egit_test,sam/htmlunit-rhino-fork,tntim96/rhino-apigee,InstantWebP2P/rhino-android,tntim96/htmlunit-rhino-fork,sam/htmlunit-rhino-fork,rasmuserik/rhino,AlexTrotsenko/rhino,swannodette/rhino,tejassaoji/RhinoCoarseTainting,lv7777/egit_test,InstantWebP2P/rhino-android,rasmuserik/rhino,qhanam/rhino,qhanam/rhino,sam/htmlunit-rhino-fork,tntim96/rhino-jscover-repackaged,lv7777/egit_test,sam/htmlunit-rhino-fork,swannodette/rhino,swannodette/rhino,tuchida/rhino,sainaen/rhino,lv7777/egit_test,Angelfirenze/rhino,tntim96/rhino-jscover,AlexTrotsenko/rhino,Pilarbrist/rhino,sainaen/rhino,swannodette/rhino,jsdoc3/rhino,swannodette/rhino,Pilarbrist/rhino,sam/htmlunit-rhino-fork,jsdoc3/rhino,tntim96/rhino-jscover,tuchida/rhino,AlexTrotsenko/rhino,sainaen/rhino,tuchida/rhino,tntim96/rhino-jscover-repackaged,Angelfirenze/rhino,jsdoc3/rhino,tejassaoji/RhinoCoarseTainting,tuchida/rhino,Angelfirenze/rhino,tuchida/rhino,Pilarbrist/rhino,Pilarbrist/rhino,qhanam/rhino,sainaen/rhino,AlexTrotsenko/rhino,sainaen/rhino,Angelfirenze/rhino,Angelfirenze/rhino,AlexTrotsenko/rhino