Large buffer of non C++ text results in RangeError: Maximum call stack size exceeded #2

Closed
opened 2023-01-29 13:27:35 +01:00 by heyman · 1 comment
heyman commented 2023-01-29 13:27:35 +01:00 (Migrated from github.com)

Hi!

Using the C++ parser in Codemirror together with a large buffer of HTML text results in a RangeError: Maximum call stack size exceeded error.

image

The following code in the Try Codemirror reproduces the error:

import {basicSetup, EditorView} from "codemirror"
import { cpp } from "@codemirror/lang-cpp"

let view = new EditorView({
  doc: getContent(),
  extensions: [
    basicSetup,
    cpp(),
  ],
  parent: document.body
})


function getContent() {
  const urlStr = `<url>
<loc>https://example.org</loc>
</url>`
  return `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${[...Array(500)].map(() => urlStr).join("\n")}
</urlset>
`;
}

I understand that this is not proper use of the C++ parser, and I don't expect it to produce good syntax highlighting for that content, but I guess that it still shouldn't throw an exception. I imagine it could cause issues for an editor that lets the user manually change the current language if they accidentally chooses C++ for a large HTML-file.

Hi! Using the C++ parser in Codemirror together with a large buffer of HTML text results in a `RangeError: Maximum call stack size exceeded` error. <img width="680" alt="image" src="https://user-images.githubusercontent.com/54217/215325408-e8de5388-f9f6-469e-8854-1e37334d459a.png"> The following code in the [Try Codemirror](https://codemirror.net/try/?c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQgeyBjcHAgfSBmcm9tICJAY29kZW1pcnJvci9sYW5nLWNwcCIKCmxldCB2aWV3ID0gbmV3IEVkaXRvclZpZXcoewogIGRvYzogZ2V0Q29udGVudCgpLAogIGV4dGVuc2lvbnM6IFsKICAgIGJhc2ljU2V0dXAsCiAgICBjcHAoKSwKICBdLAogIHBhcmVudDogZG9jdW1lbnQuYm9keQp9KQoKCmZ1bmN0aW9uIGdldENvbnRlbnQoKSB7CiAgY29uc3QgdXJsU3RyID0gYDx1cmw+Cjxsb2M+aHR0cHM6Ly9leGFtcGxlLm9yZzwvbG9jPgo8L3VybD5gCiAgcmV0dXJuIGA8P3htbCB2ZXJzaW9uPSIxLjAiIGVuY29kaW5nPSJVVEYtOCI/Pgo8dXJsc2V0IHhtbG5zPSJodHRwOi8vd3d3LnNpdGVtYXBzLm9yZy9zY2hlbWFzL3NpdGVtYXAvMC45Ij4KJHtbLi4uQXJyYXkoNTAwKV0ubWFwKCgpID0+IHVybFN0cikuam9pbigiXG4iKX0KPC91cmxzZXQ+CmA7Cn0=) reproduces the error: ```javascript import {basicSetup, EditorView} from "codemirror" import { cpp } from "@codemirror/lang-cpp" let view = new EditorView({ doc: getContent(), extensions: [ basicSetup, cpp(), ], parent: document.body }) function getContent() { const urlStr = `<url> <loc>https://example.org</loc> </url>` return `<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> ${[...Array(500)].map(() => urlStr).join("\n")} </urlset> `; } ``` I understand that this is not proper use of the C++ parser, and I don't expect it to produce good syntax highlighting for that content, but I guess that it still shouldn't throw an exception. I imagine it could cause issues for an editor that lets the user manually change the current language if they accidentally chooses C++ for a large HTML-file.
marijnh commented 2023-01-31 13:56:13 +01:00 (Migrated from github.com)

It seems github.com/lezer-parser/lr@84bb8aaf89 wasn't quite strict enough. Attached patch reduces the limit, which seems to resolve this (released as @lezer/lr 1.3.2).

It seems https://github.com/lezer-parser/lr/commit/84bb8aaf89940bd67b2e1fb9491d40c9e4098b30 wasn't quite strict enough. Attached patch reduces the limit, which seems to resolve this (released as @lezer/lr 1.3.2).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/cpp#2
No description provided.