Repository navigation
contrib: stop sqlite3, awk, and yq on timeout and bound their memory - #862
Merged
Merged
Conversation
- sqlite3: attach the invocation context as the connection interrupt, stream rows to stdout (bounded buffering for -column/-table/-box), force in-memory temp storage behind a VFS that refuses host files, cap the SQLite heap at 128 MiB, and turn NOMEM panics into errors. - awk: execute through goawk's ExecuteContext so loops honor ctx. - yq: drop the process-wide evaluation lock, set yqlib security preferences once at init, and wrap each parsed operator so it checks ctx and sizes its result against an evaluation budget. - SPEC: document the contrib interpreter cancellation and limit contract.
# Conflicts: # SPEC.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the timeout and resource-limit findings for sqlite3, awk, and yq from the contrib interpreter security review. The review found no host escapes, but these commands ignored
ExecutionRequest.Timeoutand cancellation, and could exhaust host memory or disk.User-visible behavior
sqlite3
OpenContext.sqlite3 ... | head -n 3stops in ~150ms instead of buffering every row (1.2GB in 10s before).-column,-table, and-boxstill need every row to compute widths. They refuse results larger thanmax(MaxStdoutBytes, MaxFileBytes)(64 MiB when neither is set) and printsqlite3: result too large for column mode ...(exit 1).$TMPDIR(a 2.1GB host file in 6s before):temp_storeis forced toMEMORY, andPRAGMA temp_store=...is denied.SQLITE_NOMEM. That panic is now recovered and reported assqlite3: out of memory(exit 1). Before, it was already reachable through the 256 MB wasm cap, and it would crash the process inside a pipeline's left side.awk
ExecuteContext, soBEGIN{while(1){}}honors the timeout and exits 124.yq
yqEvalMuis removed, so one runtime's yq no longer blocks another's. yqlib's security preferences (env and file ops disabled) and its expression parser are set once ininit().max(256 MiB, 4 × the estimated input size).yq: evaluation exceeded the estimated N byte size limit(exit 1).BLOCK,UNION,ASSIGN_VARIABLE,CREATE_MAP), so those nodes keep the shared type and are not wrapped. Their children are still wrapped. Re-checkgrep "OperationType ==\|OperationType !=" pkg/yqlibwhen upgrading yq.SPEC
Adds a paragraph to the contrib section on how interpreters handle cancellation and limits: the details above, plus a note that
contrib/nodejsnative builtins still can't be interrupted.Tests
New regression tests, each failing before its fix:
contrib/sqlite3/sqlite3_limits_test.goSQLITE_TMPDIRpointed at a nonexistent dir (failed before with a hostopenerror)out of memorycontrib/awk/awk_limits_test.go: infinite loops inBEGINand in a main rule hit the timeout and exit 124.contrib/yq/yq_limits_test.go-raceRan:
go test(and-race) for contrib/sqlite3, contrib/awk, and contrib/yqgo testfor contrib/extras and contrib/bashtoolmake lintandmake lint-contrib: 0 issuesNot addressed (follow-ups)
s = s sdoubling still reaches 1GB (review finding 7).contrib/nodejs: goja native builtins likeJSON.stringifyon deep values can't be interrupted and recurse in Go. Fixing this needs a goja patch.