Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

diffCleanupSemantic(Lossless) can run into an infinite loop

Aperta
#7 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, typescript
Ambito
tooling

Direzione di ricerca

Esegui prima la riproduzione fornita, quindi esamina la logica citata in src/diff.ts attorno a diffCleanupSemantic e confrontala con l’implementazione Java collegata. Usa l’input diffFromDelta predisposto per verificare che il blocco sia stato risolto e conferma il comportamento documentato per gli input non validi, idealmente con una copertura di regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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:

https://github.com/google/diff-match-patch/blob/62f2e689f498f9c92dbc588c58750addec9b1654/java/src/name/fraser/neil/plaintext/diff_match_patch.java#L938-L939

        while (edit.length() != 0 && equality2.length() != 0
            && edit.charAt(0) == equality2.charAt(0)) {

But missing from the JS (and TS) version:

https://github.com/antfu/diff-match-patch-es/blob/4f35fb7fd57df68d69068cdee0780bb779f5497f/src/diff.ts#L880

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!)
Lingua principale
TypeScript
Stelle
200
Fork
6
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di antfu/diff-match-patch-es

Tutte le issue di antfu/diff-match-patch-es

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.