{"record":{"id":"7eb5bc11e43e5906","repo":"QL-Win/QuickLook","slug":"optional-header-for-rom-s-is-not-supported","errorCode":null,"errorMessage":"Optional header for ROM's is not supported.","messagePattern":"Optional header for ROM's is not supported\\.","errorType":"exception","errorClass":"PEImageParseException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.PEViewer/PEImageParser/PEImage.cs","lineNumber":190,"sourceCode":"                MajorSubsystemVersion = reader.ReadUInt16(),\n                MinorSubsystemVersion = reader.ReadUInt16(),\n                Win32VersionValue = reader.ReadUInt32(),\n                SizeOfImage = reader.ReadUInt32(),\n                SizeOfHeaders = reader.ReadUInt32(),\n                Checksum = reader.ReadUInt32(),\n                Subsystem = (ImageSubsystem)reader.ReadUInt16(),\n                DllCharacteristics = (ImageDllCharacteristics)reader.ReadUInt16(),\n                SizeOfStackReserve = reader.ReadUInt64(),\n                SizeOfStackCommit = reader.ReadUInt64(),\n                SizeOfHeapReserve = reader.ReadUInt64(),\n                SizeOfHeapCommit = reader.ReadUInt64(),\n                LoaderFlags = reader.ReadUInt32(),\n                NumberOfRvaAndSizes = reader.ReadUInt32()\n            };\n        }\n        else if (magic == 0x107)\n        {\n            throw new PEImageParseException((int)reader.BaseStream.Position - 2, \"Optional header for ROM's is not supported.\");\n        }\n        else\n        {\n            throw new PEImageParseException((int)reader.BaseStream.Position - 2, \"Optional header magic value of '0x\" + magic.ToString(\"x4\") + \"' unknown.\");\n        }\n\n        // Data Directories\n        if (reader.BaseStream.Length - reader.BaseStream.Position < OptionalHeader.NumberOfRvaAndSizes * 8) throw new PEImageParseException((int)reader.BaseStream.Position, \"Data directories incomplete.\");\n\n        OptionalHeader.DataDirectories = Create.Array((int)OptionalHeader.NumberOfRvaAndSizes, i => new ImageDataDirectory((ImageDataDirectoryName)i, reader.ReadUInt32(), reader.ReadUInt32()));\n\n        // Section Headers\n        if (reader.BaseStream.Length - reader.BaseStream.Position < CoffHeader.NumberOfSections * 40) throw new PEImageParseException((int)reader.BaseStream.Position, \"Section headers incomplete.\");\n\n        Sections = Create\n            .Enumerable(CoffHeader.NumberOfSections, i => new ImageSectionHeader\n            {\n                Name = reader.ReadBytes(8).TakeWhile(c => c != 0).ToArray().ToUTF8String(),","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.PEViewer/PEImageParser/PEImage.cs#L172-L208","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the file is a standard PE32 or PE32+ executable and not a ROM/firmware image","If the file genuinely is a ROM image, use a specialized firmware parser instead of this PE parser","Verify the file is not corrupted — a random byte corruption at the optional header offset could produce magic 0x107 coincidentally","Catch PEImageParseException and report the unsupported format to the user"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check optional header magic is PE32 or PE32+ (not ROM 0x107)\nstatic bool IsSupportedOptionalHeaderMagic(string path)\n{\n    byte[] b = File.ReadAllBytes(path);\n    if (b.Length < 0x40) return false;\n    int peOff = BitConverter.ToInt32(b, 0x3C);\n    int magicOff = peOff + 4 + 20; // after PE sig + COFF header\n    if (magicOff + 2 > b.Length) return false;\n    ushort magic = BitConverter.ToUInt16(b, magicOff);\n    return magic == 0x10b || magic == 0x20b; // PE32 or PE32+\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var image = PEImage.FromFile(path);\n}\ncatch (PEImageParseException ex) when (ex.Message.Contains(\"ROM\"))\n{\n    // ROM images are not supported by this parser\n    logger.Warn($\"Unsupported PE format (ROM): {ex.Message}\");\n}","preventionTips":["Pre-check the optional header magic before parsing if ROM images might be encountered","Use a specialized firmware parser for ROM images instead of this PE parser","Treat any ROM magic (0x107) as unsupported and skip the file"],"tags":["pe-format","binary-parsing","unsupported-format","rom"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}