Skip to content

fix: リンク・画像の解析が二乗の時間にならず、深い引用でスタックがあふれないようにする - #29

Merged
tanahiro2010 merged 5 commits into
under18dev:mainfrom
tanahiro2010:fix/parser-redos-depth
Nov 21, 2026
Merged

tanahiro2010 merged 5 commits into
under18dev:mainfrom
tanahiro2010:fix/parser-redos-depth

Conversation

@tanahiro2010

@tanahiro2010 tanahiro2010 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Markdown のパーサの 2 点を直します。

  • 閉じない [ や ]( が並ぶと、リンク・画像の正規表現が開始位置ごとに行末まで読んで戻るため、行の長さの二乗の時間がかかっていました(手元で [a]( の繰り返し 200KB に 30 秒)。ippon serve ではリクエストのたびに描画するので、その間サーバが止まります。ラベルと URL の長さに上限(1000 / 4000 文字)を付け、URL の部分は (?=(...))\N で後戻りしないようにしました。400KB で 1.4 秒ほどで、長さに比例します。
  • > > > … と引用を深く入れ子にすると、再帰でスタックがあふれて落ちていました(40KB ほど)。入れ子は 16 段までにし、それより深い > は文字のまま出します。

挙動の変更:URL が 4000 文字を超えるリンク・画像は、リンク・画像にならず文字のまま出ます(長い data: URI を直接書いた画像など)。

確認:test/markdown.test.ts にテストを足し、npm test が通ることを確かめました。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T08:32:45.144925Z bd78073 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b499b3ac7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/markdown.ts Outdated
IMAGE,
(_, alt: string, src: string, title: string | undefined) =>
`<img src="${src}" alt="${alt}">` + (title ? `<span class="img-caption">${title}</span>` : '')
hold(`<img src="${src}" alt="${alt}">`) + (title ? `<span class="img-caption">${title}</span>` : '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve code placeholders before holding image attributes

For an image with inline code in its alt text, such as ![A `B`](img.png), the first pass has already replaced the code span with a held-code token. Holding the whole <img> then nests that token inside another held value. The final replace does not scan strings returned by its callback, so parse() emits an alt value containing literal NUL-delimited indices (A \u00000\u0000) instead of the code content. This corrupts the image's accessible description and leaks internal placeholders into the generated HTML. Resolve nested tokens with attribute-safe escaping rather than leaving them inside held tags.

Useful? React with 👍 / 👎.

@tanahiro2010

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: bd7807334c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…o fix/parser-redos-depth

# Conflicts:
#	src/markdown.ts
#	test/markdown.test.ts
@tanahiro2010
tanahiro2010 merged commit b29b9eb into under18dev:main Nov 21, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

1 participant