dotnet-opa-wasm icon indicating copy to clipboard operation
dotnet-opa-wasm copied to clipboard

Fix memory overflow if WriteString exceed memory capacity

Open ben-page opened this issue 3 years ago • 6 comments

  • The memory allocated for the initial GetData wasn't reused if different data was loaded.
  • FastEvaluate() is called when _dataHeapPtr is near the end of the memory store, it can overflow the store. I created a method to check the memory capacity and grow as necessary.

ben-page avatar Feb 15 '22 18:02 ben-page

https://github.com/open-policy-agent/npm-opa-wasm/blob/3e618c84a07ba3af8d7bab75eb77395bd79d7c54/src/opa.js#L267

this library mimics what npm-opa-wasm does in terms of execution order.

christophwille avatar Feb 15 '22 18:02 christophwille

https://github.com/open-policy-agent/npm-opa-wasm/blob/3e618c84a07ba3af8d7bab75eb77395bd79d7c54/src/opa.js#L267

this library mimics what npm-opa-wasm does in terms of execution order.

I can take out the first commit, if that helps. It's a small amount of wasted memory. The second commit is the important one.

ben-page avatar Feb 15 '22 18:02 ben-page

Yes (and I just saw that npm-opa-wasm has applied memory fixes recently, so I'll have to take a look at their recent history too)

Edit: opened #38 for mem fix note above.

christophwille avatar Feb 15 '22 18:02 christophwille

Can we somehow unit test the behavior?

christophwille avatar Feb 15 '22 18:02 christophwille

Can we somehow unit test the behavior?

I think so. Give a me a couple days.

ben-page avatar Feb 16 '22 04:02 ben-page

https://github.com/open-policy-agent/npm-opa-wasm/commit/f1be838de45e3310e7c37bcebbfa387ac17c4db3 corresponding JS impl

christophwille avatar Feb 16 '22 11:02 christophwille