oli-obk / rust-pandoc

Apache License 2.0
51 stars 29 forks source link

Added heap size limit option via runtime settings #36

Closed Dexesttp closed 3 years ago

Dexesttp commented 3 years ago

Hello, and thanks a lot for this crate !

In Pandoc's "A note on security" section of the manual (link), there is a recommendation to set a heap size limit to prevent pathological corner cases. The option was however not available as of now via this crate.

The full list of "RTS" options can be found in the Haskell "Runtime control" section of the manual (link). The Runtime System options are way more extensive than the -M option, and cover a lot of use-cases that aren't needed while using pandoc in a production setting.

To support both the +RTS -M<size> -RTS setting recommended by Pandoc, and to allow adding options to the runtime system in the future, this Pull Request adds :

This way, the PandocRuntimeSystemOption enum can be extended as new parameters are supported.

Example code to use this feature :

    let mut pandoc = pandoc::new();
    pandoc.add_option(pandoc::PandocOption::RuntimeSystem(vec![
        // Limit the heap size to 512 MB while processing the arbitrary input file.
        pandoc::PandocRuntimeSystemOption::MaximumHeapMemory("512M".to_string()),
    ]));
    pandoc.add_input(&filepath);
    pandoc.set_output_format(pandoc::OutputFormat::Html5, vec![]);
    pandoc.set_output(pandoc::OutputKind::Pipe);
oli-obk commented 3 years ago

Oh, that's really great, thanks!

In Pandoc's "A note on security" section of the manual (link), there is a recommendation to set a heap size limit to prevent pathological corner cases. The option was however not available as of now via this crate.

The full list of "RTS" options can be found in the Haskell "Runtime control" section of the manual (link). The Runtime System options are way more extensive than the -M option, and cover a lot of use-cases that aren't needed while using pandoc in a production setting.

can you put the above comment as a doc comment on the RTS enum variant?

Dexesttp commented 3 years ago

can you put the above comment as a doc comment on the RTS enum variant?

Done ! I also added the first lines of the example code above, to show how this option might be used (this passes correctly through cargo test --doc).

oli-obk commented 3 years ago

Perfect, thanks!