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

Weird segfault when parsing a map in a sequence in some cases #32

Closed
leoetlino opened this issue Jan 26, 2020 · 2 comments
Closed

Weird segfault when parsing a map in a sequence in some cases #32

leoetlino opened this issue Jan 26, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@leoetlino
Copy link
Contributor

The following document causes ryml to simply crash when parsing:

- 'a': 1
  b: 2

These ones work, though:

- a: 1
  b: 2
- b: 2
  'a': 1
- b: 2
  'a': 1
  c: 3
'a': 1
b: 2
b: 2
'a': 1

Using the inline flow style for the map in the problematic document also works:

- {'a': 1, b: 2}

It looks like something goes wrong when parsing a map in a sequence, but only if the first key-value pair has a quoted key, and only if the map uses the block style.

@leoetlino
Copy link
Contributor Author

leoetlino commented Jan 26, 2020

Looks like the problem is that the indentation is mistakenly set to 4 rather than 2 from _handle_seq_impl:

if(_scan_scalar(&s)) // this also progresses the line
{
_c4dbgp("it's a scalar");
rem = m_state->line_contents.rem;
size_t skip = 0;
if(rem.begins_with(' '))
{
_c4dbgp("skipping whitespace...");
skip = rem.first_not_of(' ');
_line_progressed(skip);
rem = rem.sub(skip);
}
if(rem.begins_with(": ") || rem.ends_with(':'))
{
_c4dbgp("actually, the scalar is the first key of a map, and it opens a new scope");
addrem_flags(RNXT, RVAL); // before _push_level! This prepares the current level for popping by setting it to RNXT
_push_level();
_start_map();
_store_scalar(s);
_save_indentation(/*behind*/s.len + skip);

It appears that _save_indentation is being called with the length of the unquoted scalar.

@biojppm
Copy link
Owner

biojppm commented Jan 27, 2020

That's it, you nailed it.

biojppm added a commit that referenced this issue Jan 29, 2020
Fixes #28 #32 . Prepare emit refactor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants