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

Crash: libc++abi: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc #67

Closed
nuttyartist opened this issue Nov 11, 2023 · 13 comments

Comments

@nuttyartist
Copy link

nuttyartist commented Nov 11, 2023

Hey again Tim!

I tried to paste some HTML from HackerNews into my note app and it crashed on the convert() function. This is the HTML that was copied from the clipboard:

<meta charset='utf-8'><table border=\"0\" style=\"font-family: Verdana, Geneva, sans-serif; letter-spacing: normal; orphans: 2; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(246, 246, 239); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;\"><tbody><tr><td class=\"ind\" indent=\"0\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 10pt; color: rgb(130, 130, 130);\"><img src=\"https://news.ycombinator.com/s.gif\" height=\"1\" width=\"0\"></td><td valign=\"top\" class=\"votelinks\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 10pt; color: rgb(130, 130, 130);\"><center><a id=\"up_21885445\" class=\"clicky\" href=\"https://news.ycombinator.com/vote?id=21885445&amp;how=up&amp;auth=4ab46530c8158343f958f2cda580e250bcc8e667&amp;goto=item%3Fid%3D21884828#21885445\" style=\"color: rgb(0, 0, 0); text-decoration: none;\"><div class=\"votearrow\" title=\"upvote\" style=\"width: 10px; height: 10px; border: 0px; margin: 3px 2px 6px; background: url(&quot;triangle.svg&quot;) 0% 0% / 10px, linear-gradient(transparent, transparent) no-repeat;\"></div></a></center></td><td class=\"default\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 10pt; color: rgb(130, 130, 130);\"><div style=\"margin-top: 2px; margin-bottom: -10px;\"><span class=\"comhead\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 8pt; color: rgb(130, 130, 130);\"><a href=\"https://news.ycombinator.com/user?id=brudgers\" class=\"hnuser\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">brudgers</a><span> </span><span class=\"age\" title=\"2019-12-26T17:52:06\"><a href=\"https://news.ycombinator.com/item?id=21885445\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">on Dec 27, 2019</a></span><span> </span><span id=\"unv_21885445\"></span><span class=\"navs\">|<span> </span><a href=\"https://news.ycombinator.com/item?id=21884828#21894436\" class=\"clicky\" aria-hidden=\"true\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">next</a><span> </span><a class=\"togg clicky\" id=\"21885445\" n=\"28\" href=\"javascript:void(0)\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">[–]</a><span class=\"onstory\"></span></span></span></div><br><div class=\"comment\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 9pt; max-width: 970px; overflow-wrap: anywhere; overflow: hidden;\"><span class=\"commtext c00\" style=\"color: rgb(0, 0, 0);\">Excel alternatives might be uncountable. Implementing spreadsheet basics is an advanced beginner exercise. But even Google’s billions only get it a distant second best because Microsoft is still working hard despite the lead. Sure Google and Apple can meet most needs most of the time. They’re good enough mainly because they are free beer. Not because they are open source. Obviously.</span></div></td></tr></tbody></table>

Can you verify if you also experience this?

@tim-gromeyer
Copy link
Owner

I couldn't reproduce it with the html2md executable and the web version of MarkdownEdit (File -> import -> HTML). How did you call it and which options did u use?

@nuttyartist
Copy link
Author

nuttyartist commented Nov 11, 2023

Can you try the following code:

for (int i = 0; i < 2; i++) {
        html2md::Options options;
        options.splitLines = false;
        QString html1 = "<meta charset='utf-8'><table border=\"0\" style=\"font-family: Verdana, Geneva, sans-serif; letter-spacing: normal; orphans: 2; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(246, 246, 239); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;\"><tbody><tr><td class=\"ind\" indent=\"0\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 10pt; color: rgb(130, 130, 130);\"><img src=\"https://news.ycombinator.com/s.gif\" height=\"1\" width=\"0\"></td><td valign=\"top\" class=\"votelinks\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 10pt; color: rgb(130, 130, 130);\"><center><a id=\"up_21885445\" class=\"clicky\" href=\"https://news.ycombinator.com/vote?id=21885445&amp;how=up&amp;auth=4ab46530c8158343f958f2cda580e250bcc8e667&amp;goto=item%3Fid%3D21884828#21885445\" style=\"color: rgb(0, 0, 0); text-decoration: none;\"><div class=\"votearrow\" title=\"upvote\" style=\"width: 10px; height: 10px; border: 0px; margin: 3px 2px 6px; background: url(&quot;triangle.svg&quot;) 0% 0% / 10px, linear-gradient(transparent, transparent) no-repeat;\"></div></a></center></td><td class=\"default\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 10pt; color: rgb(130, 130, 130);\"><div style=\"margin-top: 2px; margin-bottom: -10px;\"><span class=\"comhead\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 8pt; color: rgb(130, 130, 130);\"><a href=\"https://news.ycombinator.com/user?id=brudgers\" class=\"hnuser\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">brudgers</a><span> </span><span class=\"age\" title=\"2019-12-26T17:52:06\"><a href=\"https://news.ycombinator.com/item?id=21885445\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">on Dec 27, 2019</a></span><span> </span><span id=\"unv_21885445\"></span><span class=\"navs\">|<span> </span><a href=\"https://news.ycombinator.com/item?id=21884828#21894436\" class=\"clicky\" aria-hidden=\"true\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">next</a><span> </span><a class=\"togg clicky\" id=\"21885445\" n=\"28\" href=\"javascript:void(0)\" style=\"color: rgb(130, 130, 130); text-decoration: none;\">[–]</a><span class=\"onstory\"></span></span></span></div><br><div class=\"comment\" style=\"font-family: Verdana, Geneva, sans-serif; font-size: 9pt; max-width: 970px; overflow-wrap: anywhere; overflow: hidden;\"><span class=\"commtext c00\" style=\"color: rgb(0, 0, 0);\">Excel alternatives might be uncountable. Implementing spreadsheet basics is an advanced beginner exercise. But even Google’s billions only get it a distant second best because Microsoft is still working hard despite the lead. Sure Google and Apple can meet most needs most of the time. They’re good enough mainly because they are free beer. Not because they are open source. Obviously.</span></div></td></tr></tbody></table>";
        std::string html2 = html1.toStdString();
        html2md::Converter c(html2, &options);
        c.convert();
    }

I see it happens only on the second/third time I call the paste function so I put it in a loop. Am I doing something incorrectly (other than the inefficiency of the sample code)?

@tim-gromeyer
Copy link
Owner

tim-gromeyer commented Nov 12, 2023

I still can't reproduce it, even after running it 100 times. 😞

@nuttyartist
Copy link
Author

Weird. Then it's probably something on my end. I'll investigate more and let you know.

@tim-gromeyer
Copy link
Owner

Did you found the bug?

@nuttyartist
Copy link
Author

Hey, I encountered other bugs in my code so I'll get to this one later hah. You can close this issue and I'll reopen it if I find the bug is still related to this library.

@tim-gromeyer
Copy link
Owner

Nah, there clearly must be a bug in my library so let's leave it open till we find it.

But good luck with you other problems! I would like to help you but don't have the time right now

@nuttyartist
Copy link
Author

No worries, as soon as I find something I'll let you know.

@nuttyartist
Copy link
Author

nuttyartist commented Nov 23, 2023

Hey, Tim. I'm back to debug this issue. For some reason the debugger doesn't show any meaningful stuff.

Screen Shot 2023-11-23 at 8 56 54 PM

This is basically all I'm doing in my code:

const QMimeData *clipboardMimeData = m_clipboard->mimeData();

if (clipboardMimeData->hasHtml()) {
    qDebug() << "Hello 1";
    html2md::Options options;
    qDebug() << "Hello 2";
    options.splitLines = false;
    qDebug() << "Hello 3";
    std::string html = clipboardMimeData->html().toStdString();
    qDebug() << "Hello 4";
    html2md::Converter c(html, &options);
    qDebug() << "Hello 5";
    std::string result = c.convert();
    qDebug() << "Hello 6";
    QString markdown = QString::fromStdString(result);
    qDebug() << "Hello 7";
    pasteMarkdown(markdown);
    qDebug() << "Hello 8";
}

Hello 5 is shown tho, so I guess it's something to do with c.convert()? Maybe you can try this code out (m_clipboard is just QClipboard *m_clipboard).

It crashes when I copy a bunch of things from HackerNews, for example, a bunch of my comments together: https://news.ycombinator.com/threads?id=rubymamis

@tim-gromeyer
Copy link
Owner

Can I find the exact code (of the whole program) somewhere? And could you please embed the HTML in the code? Because when I copy comments from the site, it copies them as plain text

@tim-gromeyer
Copy link
Owner

I think I found where it crashes. In table.cpp

tim-gromeyer added a commit that referenced this issue Nov 25, 2023
@tim-gromeyer
Copy link
Owner

It should work now. Can you please test it? If it works I'll create a new release

@nuttyartist
Copy link
Author

Yay, it works! Thanks a lot.

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

No branches or pull requests

2 participants