shithub: libmujs

Download patch

ref: 505751a54e61abbe98a2081930dfe09915626cf2
parent: 41625ec2d007c65bb39e89d4b4a49236a16be558
author: Tor Andersson <tor.andersson@artifex.com>
date: Mon Dec 11 08:22:23 EST 2017

Fix issue #55: Stack overflow bug in Array.prototype.sort().

--- a/jsarray.c
+++ b/jsarray.c
@@ -292,6 +292,7 @@
 	len = js_getlength(J, 0);
 
 	hasfn = js_iscallable(J, 1);
+	hasx = hasy = 0;
 
 	for (i = 1; i < len; ++i) {
 		k = i;
@@ -306,8 +307,11 @@
 				js_setindex(J, 0, k - 1);
 				js_delindex(J, 0, k);
 			}
+			hasx = hasy = 0;
 			--k;
 		}
+		if (hasx + hasy > 0)
+			js_pop(J, hasx + hasy);
 	}
 
 	js_copy(J, 0);