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

edit_file and apply_patch corrupt every non-UTF-8 byte in the file

Chiusa
#159 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
desktop, tooling

Direzione di ricerca

Start with src/main/tools/files.ts around edit_file, apply_patch.ts at the cited update paths, and write_file's overwrite path; inspect planPatch and the existing unit tests. Add a Windows-1252 fixture to verify non-UTF-8 bytes are refused without rewriting the file, then run the relevant tests. Done when all three write paths reject bytes that fail a UTF-8 round-trip.

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

Descrizione

bug priority: high severity: high

Found in the 2026-10-07 code review and confirmed with a probe against the real tools.

Problem

edit_file (src/main/tools/files.ts:246-253) and apply_patch (apply_patch.ts:203,267) decode the whole file with readFile(file, 'utf8') and write it back as UTF-8. isBinaryFile (text_files.ts) only checks for NUL bytes, so Windows-1252, Latin-1 and Shift-JIS files pass. Every byte that isn't valid UTF-8 becomes EF BF BD, anywhere in the file, not just in the edited region. The approval diff compares the decoded strings, so it shows only the edited hunk.

Scenario

A legacy .properties file contains café in Windows-1252. The agent edits an unrelated line. The user approves a clean-looking diff, and é is replaced. The probe caf\xe9\n… came out containing ef bf bd.

Fix

Refuse to edit when the bytes don't round-trip:

const bytes = await readFile(file);
const before = bytes.toString('utf8');
if (!Buffer.from(before, 'utf8').equals(bytes))
  throw new ToolError(`${input.path} is not UTF-8; editing it would rewrite other bytes.`);

Add the same check in planPatch for updates and in write_file when it overwrites an existing file. Optionally mention the encoding in read_file's result. Add unit tests with a Windows-1252 fixture.

Lingua principale
TypeScript
Stelle
2
Fork
2
Merge medio
5h 28m
PR unite (30g)
24

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 PierrunoYT/patch

Tutte le issue di PierrunoYT/patch

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.