{"record":{"id":"f2ae6b488fdf33b3","repo":"gchq/CyberChef","slug":"invalid-or-unrecognised-file-type","errorCode":null,"errorMessage":"Invalid or unrecognised file type","messagePattern":"Invalid or unrecognised file type","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/PlayMedia.mjs","lineNumber":70,"sourceCode":"        switch (inputFormat) {\n            case \"Hex\":\n                input = fromHex(input);\n                break;\n            case \"Base64\":\n                // Don't trust the Base64 entered by the user.\n                // Unwrap it first, then re-encode later.\n                input = fromBase64(input, undefined, \"byteArray\");\n                break;\n            case \"Raw\":\n            default:\n                input = Utils.strToByteArray(input);\n                break;\n        }\n\n\n        // Determine file type\n        if (!isType(/^(audio|video)/, input)) {\n            throw new OperationError(\"Invalid or unrecognised file type\");\n        }\n\n        return input;\n    }\n\n    /**\n     * Displays an audio or video element that may be able to play the media\n     * file.\n     *\n     * @param {byteArray} data Data containing an audio or video file.\n     * @returns {string} Markup to display a media player.\n     */\n    async present(data) {\n        if (!data.length) return \"\";\n\n        const types = detectFileType(data);\n        const matches = /^audio|video/.exec(types[0].mime);\n        if (!matches) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/PlayMedia.mjs#L52-L88","documentation":"Play Media only handles audio or video. In run(), isType(/^(audio|video)/, input) checks the decoded bytes against CyberChef's file-type magic-byte signatures and returns true only if a matching audio/* or video/* type is found. If no known media signature matches, the op refuses to proceed because present() could not build a playable element.","triggerScenarios":"Feeding a non-media file (image, document, archive, text); a media file whose signature CyberChef does not recognise; truncated bytes missing the magic header; choosing the wrong 'Input format' so the bytes are mis-decoded and no signature matches.","commonSituations":"Passing an image or PDF to Play Media; a Base64 string parsed as Raw (or vice versa) destroying the magic bytes; a corrupted or truncated media file; a media container CyberChef's FileType library does not catalogue.","solutions":["Confirm the input is actually an audio or video file.","Match the 'Input format' arg to your data (Raw / Base64 / Hex) so the magic bytes survive decoding.","For Base64 media, select 'Base64' so it is unwrapped before type detection.","Verify the file plays in a normal player; if CyberChef lacks the signature, it simply cannot play that container."],"exampleFix":"// before: image bytes passed as Raw\nrun(imageBytesStr, [\"Raw\"]);  // not audio/video\n\n// after: actual media with correct format\nrun(mediaBase64, [\"Base64\"]);","handlingStrategy":"validation","validationCode":"import { isType } from \"../lib/FileType.mjs\";\nconst bytes = inputFormat === \"Hex\" ? fromHex(input) : inputFormat === \"Base64\" ? fromBase64(input, undefined, \"byteArray\") : Utils.strToByteArray(input);\nif (!isType(/^(audio|video)/, bytes)) {\n  throw new Error(\"Input is not a recognised audio or video file\");\n}\nreturn playMedia.run(input, [inputFormat]);","typeGuard":"function isRecognisedMedia(bytes) {\n  return isType(/^(audio|video)/, bytes);\n}","tryCatchPattern":"try {\n  return playMedia.run(input, [inputFormat]);\n} catch (e) {\n  if (e.message === \"Invalid or unrecognised file type\") {\n    // prompt user to supply a real audio/video file and the correct format\n  }\n  throw e;\n}","preventionTips":["Confirm the file is audio or video before selecting Play Media.","Match the Input format to the data so magic bytes survive decoding.","Validate the file plays in a normal player first."],"tags":["media","file-type","input-validation","audio","video"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}