-
Notifications
You must be signed in to change notification settings - Fork 2k
Limit maximum output of 'inspect' #1771
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
Conversation
@IvanGoncharov Right, this needs to be fixed in Python as well. I had first used |
in the current stable release, inspect causes RangeError in this line from "values.js"
when please merge this fix! |
@IvanGoncharov Looks good to me. Maybe for the sake of safety and consistency we should still restrict the number of object properties even if node,js doesn't do this? This could be implemented very similar to how you do it with arrays (i.e. also giving a hint how many entries were left out). Also, I wonder whether we should truncate long strings as well (those returned by JSON.stringify(), String(), and custom inspect functions)? Again, there should be an ellipsis with a hint how many chars were left out when this happens. |
Probably you should also increment |
Particularly, trim recursive or overly nested structures. Replicates some ideas from graphql/graphql-js#1771 but truncates strings like in pytest, and puts an ellipsis in the middle of long lists, dicts, sets etc. This is done to avoid server memory and performance issues.
f7935c5
to
5eb3bb6
Compare
@Cito Addressed in 8f2c383 |
@IvanGoncharov with that check you can only avoid direct recursions, but not larger circles like this: a = {}
b = {}
a.inspect = () => b
b.inspect = () => a
inspect(a) // -> Maximum call stack size exceeded |
Thanks for the great test case 👍 |
Nice. You only mentioned 8f2c383 which was not sufficient, but the actual fix is 2700388 which does the job and I agree is the best solution - both keeping track of seen objects and limiting the track record (recursion depth). Btw, the |
@Cito In theory entire In the future, we can add detection of dev/prod builds and do something similar to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review: I probably would have picked the same limits as node
, but this seems like a good enough improvement that I'm happy with it as-is!
@@ -9,40 +9,102 @@ | |||
|
|||
import nodejsCustomInspectSymbol from './nodejsCustomInspectSymbol'; | |||
|
|||
const MAX_ARRAY_LENGTH = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be customizeable values? I realize these match, for instance, the current console.log
max depth. For now it is probably better to hard-code, as we can always open up a customizeable option in the future, whereas if we supply that option now we can't easily take it back.
@mjmahone Thanks for the review 👍
Since DoS scenario described in #1753 based on |
It's a partial fix for #1753
I basically copied how Node.js
inspect
limits output but with different limits:10
array items instead of100
2
levels of recursion instead of3
Note: Node.js
inspect
has no limits on the max number of properties inside the object so I didn't add it either.@mjmahone Can you please take a look?
@Cito AFAIK Python version also has this problem. So it would be great if you also review it.
Note: It doesn't fully fix #1753 since you can still produce a huge number of errors but at least those error messages become shorter in most of the cases.