-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coerceToString
can overflow the stack, the bad way
#10240
Comments
For that specific case, it seems that we could just detect the recursion with blackhole-ing? In the general case that might not be possible (or maybe it is?), so yeah, some nicer stacktrace would be very useful |
This recursion is productive, whereas blackhole works for recursions that aren't productive. Unnecessary detail: |
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index bbccfcd29..02cd968ea 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -2327,6 +2327,7 @@ BackedStringView EvalState::coerceToString(
.withTrace(pos, errorCtx)
.debugThrow();
}
+ v.mkBlackhole();
return coerceToString(pos, *i->value, context, errorCtx,
coerceMore, copyToStore, canonicalizePath);
} $ nix eval --expr 'let x = { outPath = x; }; in "${x}"'
error: infinite recursion encountered
at «string»:1:31:
1| let x = { outPath = x; }; in "${x}"
| It technically is. It might not be fully correct (it might leave some unwanted blackholes around), but something like the value printer who keeps a track of the values already seen would. |
Interesting. Maybe all it needs to do is restore afterwards, like |
Describe the bug
Haven't spotted this in the wild, but:
Of course here there's little a trace would add, but a real-world case doesn't have the luxury of a single line.
Steps To Reproduce
As above. Maybe add some fluff to make it realistic.
Expected behavior
Print positions, stack trace. Leverage the language call stack #9617
Perhaps use a different counter, because these are technically not calls in the language.
Tail recursion or a loop seem feasible, but over-engineered, and a limit is desirable in practice.
nix-env --version
output2.21
Additional context
Any C++-level recursion is susceptible. It'd be great to audit the code base using a static analysis tool. Doesn't have to run in CI in my opinion, so a tool with false positives is ok.
Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: