QL-Win/QuickLook · error · InvalidDataException

Not a valid ar file

Error message

Not a valid ar file

What it means

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.

Source

Thrown at QuickLook.Plugin/QuickLook.Plugin.AppViewer/PackageParsers/Deb/ArReader.cs:36

using System.Collections.Generic;
using System.IO;
using System.Text;

namespace QuickLook.Plugin.AppViewer.PackageParsers.Deb;

public static class ArReader
{
    public static ArEntry[] Read(string filePath)
    {
        var entries = new List<ArEntry>();

        using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
        using var br = new BinaryReader(fs);

        // Check ar magic
        var magic = br.ReadBytes(8);
        if (Encoding.ASCII.GetString(magic) != "!<arch>\n")
            throw new InvalidDataException("Not a valid ar file");

        while (fs.Position < fs.Length)
        {
            var header = br.ReadBytes(60);
            if (header.Length < 60)
                break;

            string name = Encoding.ASCII.GetString(header, 0, 16).Trim();
            string sizeStr = Encoding.ASCII.GetString(header, 48, 10).Trim();
            string fmag = Encoding.ASCII.GetString(header, 58, 2);
            if (fmag != "`\n")
                throw new InvalidDataException("Invalid header end");

            long size = long.Parse(sizeStr);

            byte[] data = br.ReadBytes((int)size);

            // Completion alignment: ar file is evenly aligned

View on GitHub (pinned to cb5d9c429c)

Solutions

  1. Confirm the file genuinely is a .deb/ar archive by checking the first 8 bytes before calling ArReader.Read.
  2. Re-download the package if it may be truncated or corrupt.
  3. Verify file size is reasonable (> 100 bytes) and the magic bytes are intact.
  4. Catch InvalidDataException and report the file as not a valid Debian package.

Example fix

// before
var ar = ArReader.Read(path);

// after
using var fs = File.OpenRead(path);
var magic = new byte[8]; fs.Read(magic, 0, 8); fs.Close();
if (System.Text.Encoding.ASCII.GetString(magic) != "!<arch>\n")
    throw new InvalidDataException($"{path} is not a valid ar/deb file.");
var ar = ArReader.Read(path);
Defensive patterns

Strategy: validation

Validate before calling

// Validate the ar magic before calling ArReader.Read.
public static bool IsArArchive(string path)
{
    try
    {
        using var fs = File.OpenRead(path);
        var magic = new byte[8];
        return fs.Read(magic, 0, 8) == 8
            && System.Text.Encoding.ASCII.GetString(magic) == "!<arch>\n";
    }
    catch { return false; }
}

Try / catch

try { var ar = ArReader.Read(path); }
catch (InvalidDataException ex) when (ex.Message == "Not a valid ar file")
{
    // File is not a Unix ar / Debian package; reject or try another format.
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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