ajv-validator / ajv-cli

Command-line interface for Ajv JSON Validator
https://ajv.js.org
MIT License
264 stars 67 forks source link

error: Maximum call stack size exceeded with schemas having ~510 properties or more #134

Open ssbarnea opened 3 years ago

ssbarnea commented 3 years ago

I recently discovered that bigger generated schemas can easily produce a a error: Maximum call stack size exceeded, even when the checks are quite simple.

ajv -- validate --strict=false --errors=json -s f/ansible-playbook.json -d /Users/ssbarnea/c/a/schemas/examples/playbooks/run.yml
schema f/ansible-playbook.json is invalid
error: Maximum call stack size exceeded

Based on my initial tests 500 properties worked but 1000 generated this error, which is a very low number. My expectation that that I will likely need 10k in the end. I tested with 510 and job only one schema failing instead of both, with 550 both failed. Clearly the moment it starts to fail is just after 500.

I am not sure what is confusing the loader because in the end the entries are very simple.

Here is one file that has ~1000 entries https://sbarnea.com/ss/ansible-playbook.json and is only ~100kb, just removing some of the properties will make it pass.

epoberezkin commented 3 years ago

There are some options that toggle how code is generated - expression or loop - e.g. loopRequired.

ssbarnea commented 3 years ago

I did not see any options on the cli and I already started the process of fully replacing the ajv with code from vscode json-language-server package, especially as that is how I expect the schemas to be used primarily.

I suppose I could give it another try and try to use ajv library directly.

ssbarnea commented 3 years ago

Now that I managed to replace the cli call with native js call, I can confirm that tunning loopRequired does not solve any problems. This means that this bug applies to ajv itselt and not ajv-cli.

@epoberezkin Could you be so kind to use transfer option to move this bug to ajv project? Thanks.