michalmuskala / jason

A blazing fast JSON parser and generator in pure Elixir.
Other
1.6k stars 170 forks source link

json_map may acidentally bind over large values #94

Closed josevalim closed 4 years ago

josevalim commented 4 years ago

So json_map today has a flaw in that it creates a closure and that can accidentally close over a large objects. For example, Nebo15/logger_json library does this:

https://github.com/Nebo15/logger_json/blob/e041318e496affdfc44226c33dac38e98a37695a/lib/logger_json/plug/metadata_formatters/google_cloud_logger.ex#L23

Since conn.method is being passed to json_map, a closure pointing to conn will be created. Then the whole conn is sent to the Logger process, which may cause spikes in memory usage.

The fix is logger_json is simple but, since json_map is somewhat changing the semantics of the code, it may be worth fixing it in Jason instead?