{"record":{"id":"bcf66aa34d8135d2","repo":"QL-Win/QuickLook","slug":"not-a-valid-ar-file","errorCode":null,"errorMessage":"Not a valid ar file","messagePattern":"Not a valid ar file","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.AppViewer/PackageParsers/Deb/ArReader.cs","lineNumber":36,"sourceCode":"using System.Collections.Generic;\nusing System.IO;\nusing System.Text;\n\nnamespace QuickLook.Plugin.AppViewer.PackageParsers.Deb;\n\npublic static class ArReader\n{\n    public static ArEntry[] Read(string filePath)\n    {\n        var entries = new List<ArEntry>();\n\n        using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);\n        using var br = new BinaryReader(fs);\n\n        // Check ar magic\n        var magic = br.ReadBytes(8);\n        if (Encoding.ASCII.GetString(magic) != \"!<arch>\\n\")\n            throw new InvalidDataException(\"Not a valid ar file\");\n\n        while (fs.Position < fs.Length)\n        {\n            var header = br.ReadBytes(60);\n            if (header.Length < 60)\n                break;\n\n            string name = Encoding.ASCII.GetString(header, 0, 16).Trim();\n            string sizeStr = Encoding.ASCII.GetString(header, 48, 10).Trim();\n            string fmag = Encoding.ASCII.GetString(header, 58, 2);\n            if (fmag != \"`\\n\")\n                throw new InvalidDataException(\"Invalid header end\");\n\n            long size = long.Parse(sizeStr);\n\n            byte[] data = br.ReadBytes((int)size);\n\n            // Completion alignment: ar file is evenly aligned","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.AppViewer/PackageParsers/Deb/ArReader.cs#L18-L54","documentation":"Thrown by ArReader.Read when the first 8 bytes of the file do not equal the Unix ar archive magic '!<arch>\\n'. This guards against passing non-ar files to the Debian package parser, since .deb packages are ar archives containing control.tar and data.tar members.","triggerScenarios":"Calling ArReader.Read(filePath) on a file that is not a Unix ar archive: a raw .tar, .deb that is actually a different container, a gzip/xz stream, or a text file. Also fires on a corrupt/truncated .deb whose header bytes are wrong.","commonSituations":"A file mislabeled .deb; a .deb downloaded incompletely; passing a .udeb or a converted package with a non-standard header; feeding a plain tar.gz where a .deb was expected.","solutions":["Confirm the file genuinely is a .deb/ar archive by checking the first 8 bytes before calling ArReader.Read.","Re-download the package if it may be truncated or corrupt.","Verify file size is reasonable (> 100 bytes) and the magic bytes are intact.","Catch InvalidDataException and report the file as not a valid Debian package."],"exampleFix":"// before\nvar ar = ArReader.Read(path);\n\n// after\nusing var fs = File.OpenRead(path);\nvar magic = new byte[8]; fs.Read(magic, 0, 8); fs.Close();\nif (System.Text.Encoding.ASCII.GetString(magic) != \"!<arch>\\n\")\n    throw new InvalidDataException($\"{path} is not a valid ar/deb file.\");\nvar ar = ArReader.Read(path);","handlingStrategy":"validation","validationCode":"// Validate the ar magic before calling ArReader.Read.\npublic static bool IsArArchive(string path)\n{\n    try\n    {\n        using var fs = File.OpenRead(path);\n        var magic = new byte[8];\n        return fs.Read(magic, 0, 8) == 8\n            && System.Text.Encoding.ASCII.GetString(magic) == \"!<arch>\\n\";\n    }\n    catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { var ar = ArReader.Read(path); }\ncatch (InvalidDataException ex) when (ex.Message == \"Not a valid ar file\")\n{\n    // File is not a Unix ar / Debian package; reject or try another format.\n}","preventionTips":["Check the 8-byte ar magic before parsing.","Confirm file size is reasonable and the download is complete.","Catch InvalidDataException and report the file as not a valid .deb."],"tags":["ar","deb","magic-bytes","invaliddata","csharp"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}