Locale-dependent text IO: tasklist probe and browser launch diagnostics crash under UTF-8 mode; Common Crawl URL cache fails on non-ASCII URLs

Abierto
#2,439 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@sun04222 ya está trabajando en esto.

Desde el 24/10/2026.

  • #2440 de @sun04222 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

Start by reading browser_profiler.py, browser_manager.py, and async_url_seeder.py, focusing on the subprocess output decoding and the Common Crawl JSONL cache reads and writes described in the issue. Add tests for non-ASCII output and URLs under UTF-8 mode, then run the relevant tests. Done means all three paths handle the specified encoding cases without crashes or corrupted cache data.

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

Descripción

⚙️ In-progress ⚙️ Under Review 🐞 Bug

Summary

Three independent spots decode or write text using the platform default codec. On Windows with a non-UTF-8 ANSI codepage (cp1252/cp936) — and, more broadly, under UTF-8 mode, which becomes the default in Python 3.15 (PEP 686) — they raise UnicodeDecodeError / UnicodeEncodeError or silently corrupt data.

1. BrowserProfiler._is_browser_running (browser_profiler.py)
process = subprocess.run(["tasklist", "/FI", f"PID eq {pid}"],
                         capture_output=True, text=True)
return str(pid) in process.stdout

tasklist writes ANSI/OEM-encoded text (e.g. GBK on CJK Windows). Under UTF-8 mode the strict decode fails (observed live on a cp936 machine: 'utf-8' codec can't decode byte 0xcf in position 4). UnicodeDecodeError is a ValueError, so it escapes the except (ProcessLookupError, PermissionError, OSError) tuple. Every caller — get_builtin_browser_info(), the launch-time liveness check, and the kill loop — then treats a live builtin browser as dead, so kill/cleanup logic silently degrades and browser processes leak.

2. Chromium stdout/stderr diagnostics (browser_manager.py)

Five bytes.decode() calls decode Chromium's launch diagnostics with the strict default codec. Chromium emits ANSI/OEM-encoded messages on Windows (localized error text is common), so diagnosing an early exit can itself raise UnicodeDecodeError — converting a diagnosable launch failure into an opaque Failed to start browser: ....

3. Common Crawl URL cache (async_url_seeder.py)

_from_cc streams Common Crawl index results into a .jsonl cache and reads it back via aiofiles.open(path, "w" / "r") with no encoding. Real-world CC URLs contain raw non-ASCII characters; under cp1252/cp936 the write raises UnicodeEncodeError mid-generator (it is not caught by the httpx exception handlers), aborting the whole seeding run. A cache written under one locale also mojibakes when read back under another.

Suggested fix

Pin encoding="utf-8" at these spots (plus errors="replace" where console/subprocess output is only searched, not parsed). ASCII-only content is unaffected in all three cases. Patch and tests incoming as a PR.

Lenguaje dominante
Python
Estrellas
87.2k
Forks
9.1k
Merge medio
1 d 6 h
PR fusionados (30 d)
25

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de unclecode/crawl4ai

Todos los issues de unclecode/crawl4ai

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.