jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

A problem about calling sort function with long array

Open ayuan0828 opened this issue 1 year ago • 4 comments

Version: JerryScript 2.4.0

Description:

When I run the following program, I have an interesting discovery that jerryscript can neither output "right" normally, just like hermes; At the same time, it will not report overflow errors like xs. I think it may have some problems.

Test case:

a = [];
a.length = 0xfffff;
a.sort();
print("right");

Output of jerryscript:


Output of hermes:

right

Output of xs:

Error: stack overflow

ayuan0828 avatar Mar 16 '23 02:03 ayuan0828

I think ecma_deref_ecma_string (prop_name_p); is missing at the end of the first loop in ecma_builtin_array_prototype_object_sort

aksdfauytv avatar Mar 17 '23 05:03 aksdfauytv

May I ask if there is a problem when judging whether the length of the array is valid?

Is it executing this part of the code and exiting the loop directly?

 if (ECMA_IS_VALUE_ERROR (get_desc))
    {
      ecma_collection_free (array_index_props_p);
      ecma_deref_ecma_string (prop_name_p);
      return get_desc;
    }

Ginni1110 avatar Mar 17 '23 09:03 Ginni1110

When I try to execute print (a), if a.length=0xffff, it can output, but if a.length=0xfffff, it cannot. Perhaps this is a problem with handling stack overflows without printing output to the console?

ayuan0828 avatar Mar 17 '23 14:03 ayuan0828

I checked the latest (1a2c04763aba49f52b1537acd3730098c873511c) jerry, and I got JERRY_FATAL_OUT_OF_MEMORY for this example. It fails when it copies the data into an internal sort buffer.

zherczeg avatar Mar 24 '23 15:03 zherczeg