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

Fix buffer overflow in Markdown parser #10891

Merged
merged 1 commit into from
May 25, 2024

Conversation

lahwaacz
Copy link
Contributor

This fixes a buffer overflow that happened when parsing a bad Markdown file with an unclosed emphasis nested in other elements, such as

> __af_err af_flip(af_array *out, const af_array in, const unsigned dim)__

This snippet comes from the ArrayFire repository [1]. The problem was found after the refactoring [2] that introduced std::string_view in the code. The std::string_view::operator[] has bounds checking enabled when the macro _GLIBCXX_ASSERTIONS is defined, which is the case of Arch Linux build system.

[1] https://github.com/arrayfire/arrayfire/blob/0a25d36238aa1eee3b775d3584937ca65b0a1807/docs/pages/matrix_manipulation.md
[2] f4e3751

@albert-github
Copy link
Collaborator

albert-github commented May 24, 2024

Buffer overflows are not god and it is nice that this can be caught by the mentioned setting.

With the "unclosed emphasis" you mean in this case the * before the out ?

@albert-github albert-github added bug needinfo reported bug is incomplete, please add additional info Markdown Markdown translation input related issue labels May 24, 2024
@lahwaacz
Copy link
Contributor Author

lahwaacz commented May 24, 2024

With the "unclosed emphasis" you mean in this case the * before the out ?

Yes, that is the token problematic for this code.

@albert-github albert-github removed the needinfo reported bug is incomplete, please add additional info label May 24, 2024
src/markdown.cpp Outdated Show resolved Hide resolved
This fixes a buffer overflow that happened when parsing a bad Markdown
file with an unclosed emphasis nested in other elements, such as

```markdown
> __af_err af_flip(af_array *out, const af_array in, const unsigned dim)__
```

This snippet comes from the ArrayFire repository [1]. The problem was
found after the refactoring [2] that introduced std::string_view in the
code. The `std::string_view::operator[]` has bounds checking enabled
when the macro `_GLIBCXX_ASSERTIONS` is defined, which is the case of
Arch Linux build system.

[1] https://github.com/arrayfire/arrayfire/blob/0a25d36238aa1eee3b775d3584937ca65b0a1807/docs/pages/matrix_manipulation.md
[2] doxygen@f4e3751
@doxygen doxygen merged commit 8ddb6bb into doxygen:master May 25, 2024
8 checks passed
@albert-github albert-github added the fixed but not released Bug is fixed in github, but still needs to make its way to an official release label May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fixed but not released Bug is fixed in github, but still needs to make its way to an official release Markdown Markdown translation input related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants