github / github/copilot-cli

edit tool corrupts non-UTF-8 bytes

Abierto
#3,732 0 comentarios 0 reacciones 0 asignados Ver en GitHub
area:tools
Lenguaje dominante
Shell
Estrellas
11.2k
Forks
1.9k
Merge medio
14 h 16 min
PR fusionados (30 d)
6

Descripción

### Describe the bug

## Summary

The `edit` tool silently corrupts files that contain bytes which are valid in
legacy single-byte codepages (e.g. CP1252) but invalid as UTF-8. The tool reads
the file as UTF-8, replaces each unmappable byte with the Unicode replacement
character `U+FFFD` (`EF BF BD`), then re-encodes the whole file back as UTF-8
when writing. The corruption affects bytes the user never intended to edit and
passes `git apply` cleanly, so it ships unnoticed.

Environment

- Copilot CLI version: 1.0.60
- Model: Claude Opus 4.7
- OS: Windows 11 / PowerShell 7
- Reproduced: 2026-06-09

### Affected version

GitHub Copilot CLI 1.0.60

### Steps to reproduce the behavior

1. Create a file containing exactly one CP1252 byte (`0xA9`, the `©` glyph):

```powershell $bytes = [System.Text.Encoding]::GetEncoding(1252).GetBytes("// Copyright © Microsoft. all rights reserved.`r`nint main() { return 0; }`r`n") [System.IO.File]::WriteAllBytes("sample.cpp", $bytes)

Verify byte 13 is 0xA9:

# … 43 6F 70 79 72 69 67 68 74 20 A9 20 4D 69 63 …

2. Ask the agent to perform any edit on the file that does not touch the
copyright line — e.g. "Capitalize the first letter of each sentence in
sample.cpp."
3. Re-inspect byte 13:
# … 43 6F 70 79 72 69 67 68 74 20 EF BF BD 20 4D 69 63 …
The single A9 byte is now EF BF BD (U+FFFD "REPLACEMENT CHARACTER").
The character © is gone; git diff shows a spurious modification on a
line the agent was never asked to touch.

### Expected behavior

The edit tool should either:

- (preferred) preserve the original file's byte-level encoding — detect
the source encoding once, decode/encode round-trip-cleanly, and never emit
U+FFFD for bytes that were valid in the source; or
- (fallback) refuse to write the file and surface a clear error when it
would introduce a U+FFFD byte that did not exist in the input.

In either case the tool must never silently replace bytes outside the
diff hunk the model authored.

### Additional context

Actual behavior

The file is round-tripped through String / UTF-8 decode-encode. Every byte
in the input that is not a valid UTF-8 sequence is replaced with EF BF BD.
The replacement happens before the diff/patch logic sees the file, so it is
invisible to the model and to any patch-level review.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Reproduce el problema con los comandos de PowerShell y sample.cpp descritos en el informe; después, inspeccione los bytes originales y editados alrededor del valor CP1252 0xA9. Siga las etapas de lectura, codificación y diff/patch de la herramienta de edición para determinar dónde se introduce U+FFFD. Se considera terminado cuando se preservan los bytes no modificados o se rechaza la escritura con un error claro, respaldado por una prueba de regresión para el caso descrito.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
powershell
Área
cli, tooling
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.