Skip to content

PDF to image conversions crash the process: Unrecoverable error: rangecheck in setscreen (MagickDelegateError) #790

Description

@GITChunmei

PDF → image conversions crash the process: "Unrecoverable error: rangecheck in setscreen" (MagickDelegateError)

Describe the bug

Any PDF → image conversion (e.g. To Jpg, To Png (paged)) crashes File Converter on v2.2 (also reproduced on v2.1). The main window opens, but the conversion never starts; the process dies silently with no error in the diagnostics log (which stops at Show page Main.). Windows Error Reporting records AppCrash_FileConverter.exe with exception ImageMagick.MagickDelegateError (faulting module Magick.NET-Q16-AnyCPU, version 14.10.2.0).

No output files are produced.

To reproduce

  1. Right-click any PDF → Convert to → To Jpg
  2. The main page opens, then the process crashes / exits without producing any JPG

Root cause analysis

Analysis, reproduction and fix design were performed by a DeepSeek AI assistant; the user only executed the installation/verification steps per the assistant's instructions.

  1. ConversionJob_ImageMagick.GetOutputFilesCount() reads the PDF with Density(1, 1) to count pages. ImageMagick's PDF delegate then invokes Ghostscript with -r1x1. At 1 dpi, Ghostscript aborts with:

    Unrecoverable error: rangecheck in setscreen
    Operand stack:
        0.0624961  0  --nostringval--
    

    This reproduces on Ghostscript 10.02.1 and 10.07.1, in both subprocess (gswin64c.exe) and library (SetGhostscriptDirectory → gsdll64.dll) modes.

  2. GetOutputFilesCount() runs before Initialize() in PrepareConversion(), i.e. before MagickNET.SetGhostscriptDirectory(...) is called, so the delegate relies on whatever Ghostscript it can auto-detect (PATH / registry). On machines without a system-wide Ghostscript install the delegate fails with exit code 127 (FailedToExecuteCommand "gswin64c.exe").

  3. Non-ASCII username: on systems with a Chinese username (e.g. C:\Users\苦寒来), the delegate subprocess receives mangled temp paths (the non-ASCII characters are replaced with underscores), so Ghostscript cannot find its input files and exits with code 1.

Suggested fix

  • In GetOutputFilesCount(), use a sane density for the page-count probe instead of Density(1, 1) (e.g. 72 dpi), or skip rendering entirely (e.g. use Ping where possible).
  • Call MagickNET.SetGhostscriptDirectory(...) before the page-count read.
  • Use an ASCII-safe temp directory for the delegate files on systems with non-ASCII usernames.

Workaround (verified end-to-end on this machine)

  • Install Ghostscript (10.07.1) and add it to PATH
  • Place a gswin64c.exe wrapper earlier in PATH that rewrites -r1x1-r72x72 (bypasses the setscreen crash)
  • Remove the GS_DLL registry value (HKLM\SOFTWARE\GPL Ghostscript\<ver>) so Magick.NET uses the subprocess delegate (where the wrapper applies)
  • Set MAGICK_TEMPORARY_PATH to an ASCII-only directory (avoids the mangled-path issue)

Environment

  • OS: Windows 10 Pro 19045 (x64)
  • File Converter: 2.2.0.0 (also reproduced with 2.1.0.0)
  • Magick.NET: 14.10.2 (v2.2) / 14.4.0 (v2.1)
  • Ghostscript: 10.02.1 (bundled) / 10.07.1 (system)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions