[Windows] LaTeX preview: incomplete temporary USERPROFILE crashes pdfTeX when including PDFs

Aperta Adatta ai principianti
#62,533 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
latex, python
Ambito
desktop, devtools

Direzione di ricerca

Inizia da tectonic/compiler/compile_desktop.py e ispeziona texlive_environment(), dove vengono configurati home e USERPROFILE temporanei. Prepara le directory di profilo mancanti prima di avviare TeX Live, poi aggiungi test di regressione per un documento di solo testo e uno che include un PDF esistente con un nuovo profilo Windows. Il lavoro è concluso quando entrambi vengono compilati correttamente con l’ambiente di anteprima isolato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

app bug sandbox windows-os

Summary

On Windows, Codex's built-in LaTeX preview crashes in the system TeX Live pdflatex.exe when the document includes a PDF image. The same source compiles normally with the same TeX Live installation outside the preview.

A controlled reproduction isolated the trigger to the temporary Windows profile assigned by the desktop compiler helper: USERPROFILE points to a new home directory without AppData\Roaming and AppData\Local. Creating both subdirectories before the compiler starts makes the full document compile under the same restricted filesystem permissions. Preparing those directories for the actual desktop preview also made compile_latex_document return kind: success for the unchanged source.

Environment

  • Codex Windows package: OpenAI.Codex 26.1111.9664.0, x64.
  • Windows 10 Pro, version 10.0.19045, x64.
  • TeX Live 2026: pdfTeX 3.141592653-2.6-1.40.29, Xpdf 4.06.
  • latexmk 4.88.
  • Surface: built-in .tex editor / Compile PDF / compile_latex_document.
  • Verified on 2026-11-19.

Actual behavior

The first compiler attempt processes all pages and fonts, then crashes before printing Output written on .... Windows displays a pdflatex.exe memory-read application error. latexmk surfaces it as:

Can't spawn "pdflatex ...": No error
pdflatex: Command for 'pdflatex' gave return code 255
[texlive] failed (exit 12)

A debugger attached only to a newly launched minimal test process captured 0xc0000005 inside pdftex.dll at module-relative offset 0x127a20 on this installed binary. This is an observed fault location, not proof of the precise underlying C++ defect. A separate test also returned a heap-corruption status.

The preview then tries bundled Tectonic and hits a separate launch problem:

[tectonic] [WinError 5] Access is denied.
(operation=start_compiler winerror=5 executable=windowsapps executable_read=ok)
[bundled tectonic] command/exec failed rpc=-32603 CreateProcessAsUserW failed: 5

That fallback error matches #53757. The primary issue reported here is the pdfTeX crash.

Reproduction

Use any valid small local PDF as figure.pdf and open this document in the built-in editor:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=10cm]{figure.pdf}
\end{document}

On the affected installation, this fails with the same late crash. A text-only document using the same class compiles successfully. Several unrelated PDF figures and a multi-page PDF included using pdfpages reproduced the failure.

To isolate the environment independently of the editor:

  1. Launch the same pdflatex.exe with a fresh output directory and normal inherited environment; the PDF-inclusion example succeeds.
  2. In the child process environment only, set USERPROFILE to an existing, otherwise empty temporary directory; the example crashes.
  3. Keep that same value, but create <temporary profile>\AppData\Roaming and <temporary profile>\AppData\Local before starting the child; it succeeds.

The tests were also run inside a temporary Codex sandbox with the source directory read-only and only a diagnostic output directory writable. The same failure/success distinction held. No global environment variables or permissions were changed for these controls.

Additional controls:

Change Result
Only HOME points to the temporary directory Pass
Only USERPROFILE points to the incomplete temporary directory Crash
TeX-specific home/config/cache variables redirected, without changing USERPROFILE Pass
Temporary-directory variables redirected Pass
openout_any=p Pass
Disable SyncTeX Still fails in the actual desktop compiler
Disable PDF object compression Still fails in the actual desktop compiler
Complete the temporary profile's AppData directories, retaining all preview environment overrides Pass, full 18-page report

Installed helper observation

Read-only inspection of the installed tectonic/compiler/compile_desktop.py shows that texlive_environment() currently creates:

home = output_directory / "home"
cache = output_directory / "tex-cache"
home.mkdir(exist_ok=True)
cache.mkdir(exist_ok=True)

It then sets HOME and USERPROFILE to home, along with isolated TEXMFHOME, TEXMFCONFIG, TEXMFVAR, TEXMFCACHE, and openout_any=p. It does not create the Windows AppData directories in that temporary profile.

Suggested fix

On Windows, synchronously prepare the temporary profile before starting TeX Live, for example:

if os.name == "nt":
    (home / "AppData" / "Roaming").mkdir(parents=True, exist_ok=True)
    (home / "AppData" / "Local").mkdir(parents=True, exist_ok=True)

Keep the existing sandbox, isolated TeX paths, -norc, and -no-shell-escape. Regression coverage should include both a text-only document and a document that includes an existing PDF, with a freshly created temporary Windows profile.

Actual integrated-preview verification

A local directory watcher was used as a compatibility workaround to prepare only the missing directories in newly created Codex preview-* folders. It did not modify Codex's package, source documents, system TeX, ACLs, or sandbox policy.

After this preparation, the original unchanged source compiled via the actual desktop tool:

{
  "kind": "success",
  "message": "The current source compiled successfully with the desktop editor's compiler."
}

The first successful-compilation attempt returned stale-project; retrying returned success. A subsequent event-driven version of the watcher also passed two fresh integrated preview compilations; a temporary comment whitespace change was used to invalidate the cached result, then reverted and compiled again. The final source hash matches the original.

This verifies the actual compiler interface; it does not establish that the separate Tectonic launch-permission issue is fixed. The directory watcher is timing-dependent, so preparation inside the helper before spawning the compiler is the preferable product fix.

Related reports

  • #48311: earlier Windows/Tectonic directory-initialization failures; comments discuss synthetic USERPROFILE and missing AppData directories, but the reported compiler/error and integrated-preview outcomes differ.
  • #53757: same bundled Tectonic CreateProcessAsUserW failed: 5 fallback error.
  • #59854: other Windows preview engine-selection/cache problems, with different primary diagnostics.

Posted with the affected user's authorization. No original documents, names, student identifiers, local user paths, screenshots, session transcripts, credentials, or raw application logs are included.

Lingua principale
Rust
Stelle
136k
Fork
21.5k
Merge medio
1m
PR unite (30g)
998

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/codex

Tutte le issue di openai/codex

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.