{"record":{"id":"bfc9ac4ab4d1dc12","repo":"xtekky/gpt4free","slug":"invalid-image-format-from-magic-code","errorCode":null,"errorMessage":"Invalid image format (from magic code).","messagePattern":"Invalid image format \\(from magic code\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/image/__init__.py","lineNumber":270,"sourceCode":"        binary_data (bytes): The binary data to check.\n\n    Raises:\n        ValueError: If the image format is not allowed.\n    \"\"\"\n    if binary_data.startswith(b\"\\xFF\\xD8\\xFF\"):\n        return \"image/jpeg\"\n    elif binary_data.startswith(b\"\\x89PNG\\r\\n\\x1a\\n\"):\n        return \"image/png\"\n    elif binary_data.startswith(b\"GIF87a\") or binary_data.startswith(b\"GIF89a\"):\n        return \"image/gif\"\n    elif binary_data.startswith(b\"\\x89JFIF\") or binary_data.startswith(b\"JFIF\\x00\"):\n        return \"image/jpeg\"\n    elif binary_data.startswith(b\"\\xFF\\xD8\"):\n        return \"image/jpeg\"\n    elif binary_data.startswith(b\"RIFF\") and binary_data[8:12] == b\"WEBP\":\n        return \"image/webp\"\n    else:\n        raise ValueError(\"Invalid image format (from magic code).\")\n\n\ndef detect_file_type(binary_data: bytes) -> tuple[str, str] | None:\n    \"\"\"\n    Detect file type from magic number / header signature.\n\n    Args:\n        binary_data (bytes): File binary data\n\n    Returns:\n        tuple: (extension, MIME type)\n\n    Raises:\n        ValueError: If file type is unknown\n    \"\"\"\n\n    # ---- Images ----\n    if binary_data.startswith(b\"\\xff\\xd8\\xff\"):","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/image/__init__.py#L252-L288","documentation":"Error \"Invalid image format (from magic code).\" thrown in xtekky/gpt4free.","triggerScenarios":"Thrown at g4f/image/__init__.py:270 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a valid image file whose magic bytes match a supported format (png, jpeg, gif, webp)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}