Query Tool: first 4 MB of a large file is loaded twice when a later chunk isn't valid UTF-8
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Inizia nel modulo pgadmin.misc.file_manager, da read_file_generator() e dal suo utilizzo da parte di load_file(), quindi esegui la riproduzione fornita con un file più grande di 4 MB contenente più avanti un byte UTF-8 non valido. Il lavoro è completato quando il contenuto viene restituito esattamente una volta usando il fallback Latin-1, mantenendo i terminatori di riga e affrontando la deprecazione segnalata di codecs.open().
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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).
- Lingua principale
- Python
- Stelle
- 3.9k
- Fork
- 908
- Merge medio
- 1g 6h
- PR unite (30g)
- 38
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pgadmin-org/pgadmin4
-
Feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pgadmin-org/pgadmin4#10426 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
pgadmin-org/pgadmin4#10361 ·
I maintainer di solito rispondono entro 1 giorno
-
Feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
pgadmin-org/pgadmin4#10272 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
pgadmin-org/pgadmin4#10157 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Feature
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
pgadmin-org/pgadmin4#10615 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pgadmin-org/pgadmin4
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
cellrishi-code/claude-skills-atlas#165 ·
I maintainer di solito rispondono entro 1 giorno
-
bug confirmed issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-webui/open-webui#32635 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Filters: ?field:ne=null matches NULL rows instead of non-NULL onesForse già presa @rshdhere l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Netflix/metaflow-service#504 ·
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
gke-labs/kube-agents#3394 ·
I maintainer di solito rispondono entro 1 giorno
-
A2A audit timestamps end in +00:00Z (invalid ISO 8601)Forse già presa @O1sumitkumar l’ha presa oggi. Apertabug good first issue help wanted python
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno