Query Tool: first 4 MB of a large file is loaded twice when a later chunk isn't valid UTF-8
Los mantenedores suelen responder en 1 día
@dev-hari-prasad ya está trabajando en esto.
Desde el 7/10/2026.
- #10508 de @dev-hari-prasad — abierto
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
Línea de trabajo
Comienza en el módulo pgadmin.misc.file_manager, en read_file_generator() y en su uso por load_file(), y después ejecuta la reproducción proporcionada con un archivo de más de 4 MB que contenga un byte UTF-8 no válido más adelante. Se considera terminado cuando el contenido se entrega exactamente una vez usando el fallback Latin-1, se conservan los finales de línea y se aborda la obsolescencia indicada de codecs.open().
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
When a file larger than 4 MB is opened in the Query Tool, and a byte that isn't valid UTF-8 appears after the first 4 MB (for example, a Latin-1 é in an otherwise UTF-8 SQL dump), the file's first 4 MB are sent to the editor twice.
load_file streams read_file_generator(file_path, enc). enc comes from check_file_for_bom_and_binary(), which only looks at the first 1024 bytes, so it is utf-8 for such a file. read_file_generator() then reads the file in 4 MB chunks and yields each chunk as it goes. When a later chunk raises UnicodeDecodeError, the except branch reopens the file with latin-1 and yields it again from the start, after the earlier chunks have already been sent. If the user then saves the file, the duplicated content is written back.
To Reproduce
- Create a file of just over 5 MB that is UTF-8 except for one Latin-1 byte near the end:
data = b"SELECT 1;\r\n" * (5 * 1024 * 1024 // 11) + b"-- caf\xe9\r\n" open("big.sql", "wb").write(data) - Read it the way
load_filedoes:
The output is 9,437,188 characters for a 5,242,884-byte file: the first 4 MB appear twice.from pgadmin.misc.file_manager import read_file_generator out = "".join(read_file_generator("big.sql", "utf-8")) print(len(data), len(out)) # 5242884 9437188
I checked this by calling the function on current master; I haven't gone through the UI with a file this size.
Expected behavior
The file's content appears exactly once, decoded as Latin-1 when it isn't valid in the detected encoding, which is what the fallback is meant to do.
Desktop
- pgAdmin version: current
master - Mode: any (the file is read on the server)
Additional context
The same function uses codecs.open(), which is deprecated as of Python 3.14.
Would you like me to open a PR that fixes both? It would check which encoding applies before yielding anything, then read the file with the built-in open() (with newline='', so line endings stay exactly as they are).
- Lenguaje dominante
- Python
- Estrellas
- 3.9k
- Forks
- 908
- Merge medio
- 1 d 6 h
- PR fusionados (30 d)
- 38
Preparar el entorno
- Incluye un Dockerfile o un 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.
Más de pgadmin-org/pgadmin4
-
Feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pgadmin-org/pgadmin4#10426 · 3 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
pgadmin-org/pgadmin4#10272 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
pgadmin-org/pgadmin4#10157 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Feature
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
pgadmin-org/pgadmin4#10615 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Housekeeping
Dificultad 5/5 Más de una semana Aptitud para principiantes 12/100
pgadmin-org/pgadmin4#10611 ·
Los mantenedores suelen responder en 1 día
Todos los issues de pgadmin-org/pgadmin4
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
521xueweihan/HelloGitHub#4025 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
aws-samples/sample-per-model-bedrock#321 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 68/100
FavioVazquez/showtime#101 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
koush/ha_scrypted#81 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
google/osv-scanner-action#147 ·