diffCleanupSemantic(Lossless) can run into an infinite loop
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 74/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- javascript, typescript
- 領域
- tooling
調査の方向性
まず提供された再現手順を実行し、次に src/diff.ts の diffCleanupSemantic 周辺にある引用されたロジックを調べ、リンク先の Java 実装と比較してください。用意された diffFromDelta 入力を使用してハングが解消されたことを検証し、無効な入力に対する文書化された動作を確認してください。できれば回帰テストのカバレッジも追加してください。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
For a specifically crafted input, diffFromDelta would produce a delta that cause diffCleanupSemantic and diffCleanupSemanticLossless to hang (infinite loop).
The documentation for diffFromDelta says that it would throw on invalid input, but it's not doing that for this case. Or this could be an issue with diffCleanupSemantic and diffCleanupSemanticLossless where they are mishandling specific diffs.
This is happening due to the empty edit/equality tuples. Reproducible on the latest v2.0.1.
Reproduction:
import { diffCleanupSemantic, diffFromDelta } from 'diff-match-patch-es'
const diffs = diffFromDelta('ac', '=1\t-0\t=0\t+b\t=1')
console.log('diff:', JSON.stringify(diffs))
diffCleanupSemantic(diffs)
Potential fix (unverified):
The original Java version has some extra check:
while (edit.length() != 0 && equality2.length() != 0
&& edit.charAt(0) == equality2.charAt(0)) {
But missing from the JS (and TS) version:
Reproduction
https://github.com/aforemendude/bugs-reproduction/tree/main/diff-match-patch-es-delta-inf-loop
System Info
System:
OS: Linux 7.0 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
CPU: (4) x64 Intel(R) N95
Memory: 12.39 GB / 15.40 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 24.18.0 - /usr/local/nodejs/bin/node
npm: 11.16.0 - /usr/local/nodejs/bin/npm
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- The provided reproduction is a minimal reproducible of the bug.
Contributions
- I am willing to submit a PR to fix this issue
- I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)
- 主要言語
- TypeScript
- スター
- 200
- フォーク
- 6
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
antfu/diff-match-patch-es のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
antfu/diff-match-patch-es の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
openedx/frontend-app-authoring#3274 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
area/documentation status/need-triage
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
google-gemini/gemini-cli#29548 ·
メンテナーはふだん 1 日以内に返信
-
sdk-typescript vector-store
難易度 2/5 半日 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信