QL-Win/QuickLook · error · PEImageParseException

Optional header for ROM's is not supported.

Error message

Optional header for ROM's is not supported.

What it means

The optional header magic value 0x107 identifies a ROM (read-only memory) image per the PE/COFF specification. This parser only supports PE32 (0x10b) and PE32+ (0x20b) — the two formats used by standard Windows executables and DLLs. ROM images use a different optional header layout that this parser does not implement, so they are explicitly rejected. The exception Offset points to the start of the 2-byte magic.

Source

Thrown at QuickLook.Plugin/QuickLook.Plugin.PEViewer/PEImageParser/PEImage.cs:190

                MajorSubsystemVersion = reader.ReadUInt16(),
                MinorSubsystemVersion = reader.ReadUInt16(),
                Win32VersionValue = reader.ReadUInt32(),
                SizeOfImage = reader.ReadUInt32(),
                SizeOfHeaders = reader.ReadUInt32(),
                Checksum = reader.ReadUInt32(),
                Subsystem = (ImageSubsystem)reader.ReadUInt16(),
                DllCharacteristics = (ImageDllCharacteristics)reader.ReadUInt16(),
                SizeOfStackReserve = reader.ReadUInt64(),
                SizeOfStackCommit = reader.ReadUInt64(),
                SizeOfHeapReserve = reader.ReadUInt64(),
                SizeOfHeapCommit = reader.ReadUInt64(),
                LoaderFlags = reader.ReadUInt32(),
                NumberOfRvaAndSizes = reader.ReadUInt32()
            };
        }
        else if (magic == 0x107)
        {
            throw new PEImageParseException((int)reader.BaseStream.Position - 2, "Optional header for ROM's is not supported.");
        }
        else
        {
            throw new PEImageParseException((int)reader.BaseStream.Position - 2, "Optional header magic value of '0x" + magic.ToString("x4") + "' unknown.");
        }

        // Data Directories
        if (reader.BaseStream.Length - reader.BaseStream.Position < OptionalHeader.NumberOfRvaAndSizes * 8) throw new PEImageParseException((int)reader.BaseStream.Position, "Data directories incomplete.");

        OptionalHeader.DataDirectories = Create.Array((int)OptionalHeader.NumberOfRvaAndSizes, i => new ImageDataDirectory((ImageDataDirectoryName)i, reader.ReadUInt32(), reader.ReadUInt32()));

        // Section Headers
        if (reader.BaseStream.Length - reader.BaseStream.Position < CoffHeader.NumberOfSections * 40) throw new PEImageParseException((int)reader.BaseStream.Position, "Section headers incomplete.");

        Sections = Create
            .Enumerable(CoffHeader.NumberOfSections, i => new ImageSectionHeader
            {
                Name = reader.ReadBytes(8).TakeWhile(c => c != 0).ToArray().ToUTF8String(),

View on GitHub (pinned to cb5d9c429c)

Solutions

  1. Confirm the file is a standard PE32 or PE32+ executable and not a ROM/firmware image
  2. If the file genuinely is a ROM image, use a specialized firmware parser instead of this PE parser
  3. Verify the file is not corrupted — a random byte corruption at the optional header offset could produce magic 0x107 coincidentally
  4. Catch PEImageParseException and report the unsupported format to the user
Defensive patterns

Strategy: try-catch

Validate before calling

// Check optional header magic is PE32 or PE32+ (not ROM 0x107)
static bool IsSupportedOptionalHeaderMagic(string path)
{
    byte[] b = File.ReadAllBytes(path);
    if (b.Length < 0x40) return false;
    int peOff = BitConverter.ToInt32(b, 0x3C);
    int magicOff = peOff + 4 + 20; // after PE sig + COFF header
    if (magicOff + 2 > b.Length) return false;
    ushort magic = BitConverter.ToUInt16(b, magicOff);
    return magic == 0x10b || magic == 0x20b; // PE32 or PE32+
}

Try / catch

try
{
    var image = PEImage.FromFile(path);
}
catch (PEImageParseException ex) when (ex.Message.Contains("ROM"))
{
    // ROM images are not supported by this parser
    logger.Warn($"Unsupported PE format (ROM): {ex.Message}");
}

Prevention

When it happens

Trigger: Passing a ROM PE image (optional header magic 0x107) to PEImage.FromFile or PEImage.FromBinary. In practice this is extremely rare because ROM images are specialized firmware artifacts not commonly encountered in desktop file-preview scenarios.

Common situations: Encountering a firmware or ROM image file; more commonly, the magic bytes at the optional header offset are corrupted and coincidentally read as 0x107, meaning the file is actually damaged rather than a genuine ROM image.

Related errors


AI-assisted analysis of QL-Win/QuickLook@cb5d9c429c (2026-08-13). Data as JSON: /api/errors/7eb5bc11e43e5906. Report an issue: GitHub.