{"record":{"id":"6f2b1c138e024b16","repo":"xtekky/gpt4free","slug":"invalid-image-format-from-mime-file-type","errorCode":null,"errorMessage":"Invalid image format (from mime file type).","messagePattern":"Invalid image format \\(from mime file type\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/image/__init__.py","lineNumber":243,"sourceCode":"    \"\"\"\n    Checks if the given data URI represents an image.\n\n    Args:\n        data_uri (str): The data URI to check.\n\n    Raises:\n        ValueError: If the data URI is invalid or the image format is not allowed.\n    \"\"\"\n    if data_uri.startswith(\"https:\") or data_uri.startswith(\"http:\"):\n        return True\n    # Check if the data URI starts with 'data:image' and contains an image format (e.g., jpeg, png, gif)\n    if not re.match(r\"data:image/(\\w+);base64,\", data_uri):\n        raise ValueError(f\"Invalid data URI image. {data_uri[:10]}...\")\n    # Extract the image format from the data URI\n    image_format = re.match(r\"data:image/(\\w+);base64,\", data_uri).group(1).lower()\n    # Check if the image format is one of the allowed formats (jpg, jpeg, png, gif)\n    if image_format not in EXTENSIONS_MAP and image_format != \"svg+xml\":\n        raise ValueError(\"Invalid image format (from mime file type).\")\n    return True\n\n\ndef is_accepted_format(binary_data: bytes) -> str:\n    \"\"\"\n    Checks if the given binary data represents an image with an accepted format.\n\n    Args:\n        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\"):","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/image/__init__.py#L225-L261","documentation":"Error \"Invalid image format (from mime file type).\" thrown in xtekky/gpt4free.","triggerScenarios":"Thrown at g4f/image/__init__.py:243 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide an image with a recognized mime type (png, jpeg, gif, webp).","Check that the file content is a valid image."],"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"}