Skip to content

builtin: check reverse's remaining memory budget before allocation - #1006

Merged
antonmedv merged 3 commits into
expr-lang:masterfrom
anishpentyala:fix/reverse-budget-before-allocation
Nov 22, 2026
Merged

antonmedv merged 3 commits into
expr-lang:masterfrom
anishpentyala:fix/reverse-budget-before-allocation

Conversation

@anishpentyala

Copy link
Copy Markdown
Contributor

Follow-up to #1003.

The Safe callback for reverse currently ignores its remaining-budget argument. It allocates and fills the output slice, then returns the memory charge for the VM to check. An over-budget call already returns a budget error, but only after the output allocation.

Check the output length against the remaining budget before allocating. Keep the existing strict boundary (size >= remaining), argument validation order, successful result and returned charge unchanged. This changes only reverse; it does not change the memory-budget model or claim to bound every builtin.

Tests cover direct callback boundaries, slices and arrays, empty/typed-nil inputs, original argument errors, nested VM calls and input preservation. A bounded allocation regression checks that rejection happens before the large output allocation; it does not assert an exact allocator byte count.

Validation: full ordinary suite on Go 1.26.6 and Go 1.18.10, root and builtin race suites, focused boundary and allocation tests repeated, go vet ./..., debugger test and git diff --check.

Signed-off-by: Anish Pentyala <Anish.n.pentyala@gmail.com>
Signed-off-by: Anish Pentyala <Anish.n.pentyala@gmail.com>
Signed-off-by: Anish Pentyala <Anish.n.pentyala@gmail.com>
@antonmedv
antonmedv merged commit 8569439 into expr-lang:master Nov 22, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants