shikijs / shiki

A beautiful yet powerful syntax highlighter
http://shiki.style/
MIT License
10.24k stars 375 forks source link

Infinite loop when parsing unclosed ansi string #517

Closed Hoofoo-WHU closed 9 months ago

Hoofoo-WHU commented 1 year ago

The root cause of this bug appears to be related to this issue, which has already been resolved. It's possible that updating to the latest version of the dependency could fix this issue in Shiki.

antfu commented 9 months ago

We temporarily closed this due to the lack of enough information. We could not identify whether it was a bug or a userland misconfiguration with the given info. Please provide a minimal reproduction to reopen the issue. Thanks.

Why reproduction is required

undefined-moe commented 3 months ago

got a repro https://jsfiddle.net/7rLk5fqa/1/ :

import { codeToHtml } from 'https://esm.sh/shiki@1.0.0';

async function main() {
  const options = {
    lang: 'ansi',
    theme: 'github-light',
  };
  document.body.innerHTML = await codeToHtml('this works', options);
  document.body.innerHTML = await codeToHtml(`but this doesn't
foo.cc: In function ‘int main()’:
foo.cc:8:13: error: expected ‘;’ before ‘}’ token
    8 |     return 0
      |             ^
      |             ;
    9 | }
      | ~            
`, options);
}

main();

(base64 encoded payload)

G1swMW0bW0tmb28uY2M6G1ttG1tLIEluIGZ1bmN0aW9uIOKAmBtbMDFtG1tLaW50G1swMTszMm0b
W0sgbWFpbhtbbRtbSygpG1ttG1tL4oCZOgogICAgG1swMW0bW0tmb28uY2M6ODoxMzobW20bW0sg
G1swMTszMW0bW0tlcnJvcjogG1ttG1tLZXhwZWN0ZWQg4oCYG1swMW0bW0s7G1ttG1tL4oCZIGJl
Zm9yZSDigJgbWzAxbRtbS30bW20bW0vigJkgdG9rZW4KICAgICAgICA4IHwgICAgIHJldHVybiAw
CiAgICAgICAgICB8ICAgICAgICAgICAgIBtbMDE7MzFtG1tLXhtbbRtbSwogICAgICAgICAgfCAg
ICAgICAgICAgICAbWzMybRtbSzsbW20bW0sKICAgICAgICA5IHwgG1szMm0bW0t9G1ttG1tLCiAg
ICAgICAgICB8IBtbMzJtG1tLfhtbbRtbSw==