Skip to content

Fix uint64_t underflow inside Array::arrayPrototypeSplice#1913

Open
farwayer wants to merge 2 commits intofacebook:static_hfrom
farwayer:arr-splice-underflow
Open

Fix uint64_t underflow inside Array::arrayPrototypeSplice#1913
farwayer wants to merge 2 commits intofacebook:static_hfrom
farwayer:arr-splice-underflow

Conversation

@farwayer
Copy link

Summary

Fixes #1912

Incorrect handling of unsigned variables causes an undeflow inside Array::arrayPrototypeSplice when calling array.splice(0). This leads to a missed call to DeleteProperty on array elements.

while (i > (len - actualDeleteCount + itemCount - 1)) {

If len == actualDeleteCount (as for array.splice(0)) result expression < 0 for uint64_t and the loop never executes.

Steps To Reproduce

An example with Proxy, which is a symptom:

let log = (...args) => typeof print === 'undefined' ? console.log(JSON.stringify(args)) : print(JSON.stringify(args))

let arr = new Proxy([], {
	deleteProperty(target, p) {
		log('del', target, p)
		return Reflect.deleteProperty(target, p)
	},
})

arr.push('a', 'b', 'c')
arr.splice(0)

Hermes

no messages

V8

["del",["a","b","c"],"2"]
["del",["a","b",null],"1"]
["del",["a",null,null],"0"]

Test Plan

["del",["a","b","c"],"2"]
["del",["a","b",null],"1"]
["del",["a",null,null],"0"]

@meta-cla meta-cla bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Feb 21, 2026
@farwayer farwayer force-pushed the arr-splice-underflow branch from eb56ffb to 49cd3d9 Compare February 21, 2026 02:44
@farwayer
Copy link
Author

I also converted the counter to uint64_t, which should speed up the loop somewhat due to cheaper operations with integer variables.
And I renamed the counter from i -> k to match the specification.

@farwayer
Copy link
Author

farwayer commented Mar 4, 2026

@lavenzg @avp @fbmal7 hi, sorry to bother, but could someone please review the pull request? If anything needs to be improved, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uint64_t underflow inside Array::arrayPrototypeSplice

1 participant