libexpr: fix stack overflow in checkMeta on deeply nested structures

This commit is contained in:
Robert Hensing
2025-11-22 22:34:37 +01:00
parent 4167686789
commit c2d2a0fe2d
2 changed files with 8 additions and 0 deletions

View File

@@ -213,6 +213,8 @@ StringSet PackageInfo::queryMetaNames()
bool PackageInfo::checkMeta(Value & v)
{
auto _level = state->addCallDepth(v.determinePos(noPos));
state->forceValue(v, v.determinePos(noPos));
if (v.type() == nList) {
for (auto elem : v.listView())

View File

@@ -40,3 +40,9 @@ fi
# produces a controlled stack overflow error rather than a segfault.
expectStderr 1 nix-instantiate --expr 'let x = { recurseForDerivations = true; more = x; }; in x' \
| grepQuiet "stack overflow; max-call-depth exceeded"
# Test that nix-env -qa --meta on deeply nested meta attributes produces a
# controlled stack overflow error rather than a segfault.
echo 'let f = n: { type = "derivation"; name = "test"; system = "x86_64-linux"; meta.nested = f (n + 1); }; in { pkg = f 0; }' > "$TEST_ROOT/deep-meta.nix"
expectStderr 1 nix-env -qa -f "$TEST_ROOT/deep-meta.nix" --json --meta \
| grepQuiet "stack overflow; max-call-depth exceeded"