commonmark / commonmark/cmark

The cmark_markdown_to_html function call uses free to release crashes

Open
#577 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
2k
Forks
691
Avg merge
1d 16h
Merged PRs (30d)
1

Description

QString DeepSeekWidgetUI::convertMarkdownToHtml(const QString& markdown)
{
QByteArray byteArray = markdown.toUtf8();
const char* markdownCString = byteArray.constData();

char* html = cmark_markdown_to_html(markdownCString, strlen(markdownCString), CMARK_OPT_DEFAULT);
if (html == NULL)
{
	return markdown;
}

QString htmlText = QString::fromUtf8(html);

free(html);

return htmlText;

}

After calling the cmark_markdown_to_html function, I copied the data to the QString, then released the memory and crashed directly. I thought it was a problem with the QString::fromUtf8() function, so I tested it and executed free() before QString::fromUtf8(), and it crashed as well.

This is the result of the call after QString::fromUtf8()
Image

This is the result of the call before QString::fromUtf8()

Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the cmark_markdown_to_html API and inspect how the returned buffer is allocated and documented; reproduce the crash with the shown Qt caller. Determine the correct ownership and release behavior, then verify that conversion and cleanup no longer crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.