Skip to content
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

std.strReplace max stack frames exceeded #531

Closed
Globegitter opened this issue Jun 21, 2018 · 5 comments
Closed

std.strReplace max stack frames exceeded #531

Globegitter opened this issue Jun 21, 2018 · 5 comments

Comments

@Globegitter
Copy link
Contributor

I am trying to import this file: https://github.com/SpiderLabs/ModSecurity/blob/v3/master/modsecurity.conf-recommended and output it as a multiline json string (without visible \n), not succeeding with it and on the way seemed to have stumbled on a bug. I am passing it in via -ext-str-file modsecurity_conf=modsecurity.conf and in my jsonnet file have

local modsecurityConf = std.extVar("modsecurity_conf");

local test = std.strReplace(modsecurityConf, 'engine', 'something');
....
local config = {
  data: {
    "modsecurity.conf": test,
  }
};
...
{
  items: [
    config,
  ],
}

I get the following error:

RUNTIME ERROR: max stack frames exceeded.
	std.jsonnet:174:15-23	object <invar>
	std.jsonnet:195:16-26	thunk <a>
	std.jsonnet:195:16-38	function <anonymous>
	std.jsonnet:195:16-38	thunk <slice>
	std.jsonnet:190:15-20	thunk <slice>
	std.jsonnet:(188:11)-(194:12)	function <build>
	std.jsonnet:(188:11)-(194:12)	function <build>
	std.jsonnet:195:7-68	function <anonymous>
	std.jsonnet:119:25-44	thunk <a>
	std.jsonnet:119:25-52	function <anonymous>
	...
	./common/jsonnet/k8s.libsonnet:276:28-50	thunk <a>
	./common/jsonnet/k8s.libsonnet:276:28-62	function <anonymous>
	./common/jsonnet/k8s.libsonnet:276:28-62	thunk <nonstrings>
	./common/jsonnet/k8s.libsonnet:277:23-33	
	./common/jsonnet/k8s.libsonnet:277:12-34	thunk <a>
	./common/jsonnet/k8s.libsonnet:277:12-39	function <anonymous>
	./common/jsonnet/k8s.libsonnet:277:12-39	thunk <object_assert>
	path/to/config.jsonnet:93:5-11	thunk <array_element>
	path/to/config.jsonnet:(91:10)-(96:4)	object <anonymous>
	During manifestation	

The example above is slightly simplified but should show off the case. I have no idea why this happens.

@Globegitter
Copy link
Contributor Author

Ahh, I see the current implementation is in jsonnet and is recursive so reaches max stack frame on a long string. I guess implementing it natively would solve the issue.

@sparkprime
Copy link
Contributor

sparkprime commented Jun 21, 2018

It's missing tailstrict in the recursive calls, that's how you avoid stack overflow in lazy functional languages:

        replace_after(new_index, new_index, acc + str[start_index:curr_index] + to) tailstrict
      else
        replace_after(start_index, curr_index + 1, acc) tailstrict;

@sparkprime
Copy link
Contributor

Can you try adding those 2 keywords, rebuild the jsonnet executable and see if it fixes it

@Globegitter
Copy link
Contributor Author

ah yes, that fixes it indeed. Should I submit a PR for it?

@sparkprime
Copy link
Contributor

Yes please!

Globegitter pushed a commit to Globegitter/jsonnet that referenced this issue Jun 22, 2018
csmarchbanks added a commit to splunk/kubernetes-mixin that referenced this issue Mar 4, 2019
This is to avoid running into this bug: google/jsonnet#531
csmarchbanks added a commit to splunk/kubernetes-mixin that referenced this issue Mar 22, 2019
This is to avoid running into this bug: google/jsonnet#531
desaintmartin pushed a commit to wiremind/kubernetes-mixin that referenced this issue Apr 18, 2019
This is to avoid running into this bug: google/jsonnet#531
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants