edit_file and apply_patch corrupt every non-UTF-8 byte in the file
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 77/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 2
- Forks
- 2
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Issues similares
-
Add: Class TV ModaAbiertocheck:passed streams:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
GiganticMinecraft/seichi-playguide#183 ·
Los mantenedores suelen responder en 1 día
-
area: core complexity: easy impact: medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
ueberdosis/tiptap#8668 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
longbridge/nsh#804 ·
Los mantenedores suelen responder en 1 día