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

Manage buffer with yaml in OCaml part of ocaml-yaml #35

Merged
merged 1 commit into from
Feb 7, 2020

Conversation

marcinkoziej
Copy link
Contributor

This fixes #17 and #33 which result from a bug in passing input buffer to yaml parser.
When a string with yaml text is passed to
yaml_parser_set_input_string, it only stores a pointer to it (not a
copy). The temporary buffer, created by the FFI from string on calling this
function is freed, and later overwritten - before being parsed by YAML parser. The corrupted input buffer makes the parsing fail.

This changes the signature of yaml_parser_set_input_string to accept char ptr,
and the char array is stored in parser type structure as long as is needed for
parsing.

There is another PR with a test containing a large yaml file #30

This fixes a bug when a string with YAML was passed to
yaml_parser_set_input_string, which would only store a pointer to it (not a
copy). The temporary buffer, created by the FFI from string on calling this
function was freed, and later overwritten - before being parsed by YAML parser.

This changes the signature of yaml_parser_set_input_string to accept char ptr,
and the char array is stored in parser type structure as long as is needed for
parsing.
Copy link
Owner

@avsm avsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent debugging and fix. Thanks for this @marcinkoziej!

@avsm avsm merged commit 080531a into avsm:master Feb 7, 2020
avsm added a commit to avsm/opam-repository that referenced this pull request Feb 7, 2020
CHANGES:

* Fix a memory unsoundness issue with larger files in the
  bindings to libyaml, which fixes spurious errors when parsing
  larger YAML files (avsm/ocaml-yaml#35 marcinkoziej)
* Expose more information about error locations while parsing
  a Yaml file (avsm/ocaml-yaml#34 @marcinkoziej)
* Add test for a large Yaml file (avsm/ocaml-yaml#30 @pmonson711)
* Bump size of internal serialisation buffer in `to_string`
  to 64KB from 16KB (@avsm).
* Switch CI to GitHub Actions (@avsm)
* Depend on dune-configurator in the build to be compatible
  with dune 2.0 and higher (@avsm)
mgree pushed a commit to mgree/opam-repository that referenced this pull request Feb 19, 2020
CHANGES:

* Fix a memory unsoundness issue with larger files in the
  bindings to libyaml, which fixes spurious errors when parsing
  larger YAML files (avsm/ocaml-yaml#35 marcinkoziej)
* Expose more information about error locations while parsing
  a Yaml file (avsm/ocaml-yaml#34 @marcinkoziej)
* Add test for a large Yaml file (avsm/ocaml-yaml#30 @pmonson711)
* Bump size of internal serialisation buffer in `to_string`
  to 64KB from 16KB (@avsm).
* Switch CI to GitHub Actions (@avsm)
* Depend on dune-configurator in the build to be compatible
  with dune 2.0 and higher (@avsm)
@avsm avsm mentioned this pull request Aug 4, 2021
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

Successfully merging this pull request may close these issues.

yaml_of_string (and yaml_to_string) fails with big inputs
2 participants