gchq/CyberChef · error · OperationError

Invalid file type.

Error message

Invalid file type.

What it means

The Parse QR Code operation checks the input ArrayBuffer's magic bytes via isImage(). If the data does not have a recognized image file signature (PNG, JPEG, GIF, BMP, etc.), it is rejected before any QR-decode attempt is made.

Source

Thrown at src/core/operations/ParseQRCode.mjs:52

            },
        ];
        // No Magic checks: detecting a QR code in arbitrary image data requires
        // actually attempting to parse one, which is expensive and produces
        // spurious "Could not read a QR code from the image" log messages for
        // any image input via Magic. Users can add Parse QR Code manually when
        // they know the image contains a QR code. See issue #2610.
    }

    /**
     * @param {ArrayBuffer} input
     * @param {Object[]} args
     * @returns {string}
     */
    async run(input, args) {
        const [normalise] = args;

        if (!isImage(input)) {
            throw new OperationError("Invalid file type.");
        }
        return parseQrCode(input, normalise);
    }
}

export default ParseQRCode;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide a recognized raster image format (PNG, JPEG, GIF, BMP) as an ArrayBuffer
  2. Convert SVG or PDF-embedded QR codes to a raster image first
  3. Ensure the input reaches the operation as ArrayBuffer, not as a string
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: verify the input is a recognized image type by magic bytes
function getImageType(buf) {
  const bytes = new Uint8Array(buf.slice(0, 8));
  if (bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4E && bytes[3] === 0x47) return 'PNG';
  if (bytes[0] === 0xFF && bytes[1] === 0xD8 && bytes[2] === 0xFF) return 'JPEG';
  if (bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46) return 'GIF';
  if (bytes[0] === 0x42 && bytes[1] === 0x4D) return 'BMP';
  return null;
}
if (!getImageType(input)) {
  throw new Error("Input is not a recognized image format (PNG, JPEG, GIF, BMP).");
}

Type guard

function isImageBuffer(buf) {
  return buf instanceof ArrayBuffer && getImageType(buf) !== null;
}

Try / catch

try {
  const result = await chef.parseQRCode(input, [false]);
} catch (e) {
  if (/Invalid file type/i.test(e.message)) {
    console.error("Provide a raster image (PNG/JPEG/GIF/BMP) as ArrayBuffer");
  } else { throw e; }
}

Prevention

When it happens

Trigger: Input is not an image: plain text, raw bytes, a PDF, a JSON payload, or binary data of any non-image type. Also fires for a truncated or corrupted image whose magic bytes were stripped. The input type must be ArrayBuffer.

Common situations: User feeds a text string or hex data instead of an image file. User provides a file that is a PDF or SVG containing a QR code (the operation needs a raster image). The image data was truncated during upload or copy, losing the header.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/434d9d126494fb98. Report an issue: GitHub.