{"record":{"id":"328e8159c29e32a1","repo":"bevyengine/bevy","slug":"invalid-data-0","errorCode":null,"errorMessage":"invalid data: {0}","messagePattern":"invalid data: (.+?)","errorType":"exception","errorClass":"TextureError","httpStatus":null,"severity":"error","filePath":"crates/bevy_image/src/image.rs","lineNumber":2308,"sourceCode":"    /// Invalid data.\n    #[error(\"invalid data: {0}\")]\n    InvalidData(String),\n    /// Transcode error.\n    #[error(\"transcode error: {0}\")]\n    TranscodeError(String),\n    /// Format requires transcoding.\n    #[error(\"format requires transcoding: {0:?}\")]\n    FormatRequiresTranscodingError(TranscodeFormat),\n    /// Only cubemaps with six faces are supported.\n    #[error(\"only cubemaps with six faces are supported\")]\n    IncompleteCubemap,\n}\n\n/// The type of a raw image buffer.\n#[derive(Debug)]\npub enum ImageType<'a> {\n    /// The mime type of an image, for example `\"image/png\"`.\n    MimeType(&'a str),\n    /// The extension of an image file, for example `\"png\"`.\n    Extension(&'a str),\n    /// The direct format of the image\n    Format(ImageFormat),\n}\n\nimpl<'a> ImageType<'a> {\n    /// Attempts to detect the appropriate [`ImageFormat`] for this image type.\n    ///\n    /// # Errors\n    ///\n    /// A [`TextureError`] will be returned if this image type is a MIME type or file extension for\n    /// an unsupported or disabled format.\n    pub fn to_image_format(&self) -> Result<ImageFormat, TextureError> {\n        match self {\n            ImageType::MimeType(mime_type) => ImageFormat::from_mime_type(mime_type)\n                .ok_or_else(|| TextureError::InvalidImageMimeType(mime_type.to_string())),\n            ImageType::Extension(extension) => ImageFormat::from_extension(extension)","sourceCodeStart":2290,"sourceCodeEnd":2326,"githubUrl":"https://github.com/bevyengine/bevy/blob/221e52ae323febfd399bd7d067918fc43648cfb3/crates/bevy_image/src/image.rs#L2290-L2326","documentation":"TextureError::InvalidData is the malformed-container error of the specialized loaders. It is raised when the KTX2 header cannot be parsed (ktx2.rs:36, \"Failed to parse ktx2 file\"), when the DDS reader fails (dds.rs:27, \"Failed to parse DDS file\"), and throughout basis.rs for invalid checksums (line 17, debug builds), invalid headers (20), missing image info (24), modulo-6 cubemap-array violations (49) and inconsistent mip level counts (72). It means the file is not a structurally valid instance of its claimed container format.","triggerScenarios":"A .dds file with a corrupted/odd header from an unusual exporter; a KTX2 v1 file renamed to .ktx2; a .basis file that failed checksum validation in a debug build; any container whose bytes were truncated or shuffled.","commonSituations":"Hand-edited or script-mangled texture files; KTX2/DDS produced by niche tools that emit non-conformant headers; assets corrupted by version-control line-ending rewriting on Windows; downloaded texture packs with broken files.","solutions":["Regenerate the file with a known-good tool: toktx for KTX2, texconv/compressonator for DDS, the official basis_universal encoder for .basis.","Verify the file is really the format its extension claims (first bytes: KTX2 magic 'KTX 20\\xBB\\r\\n', 'DDS ', '\\xAB BASIS').","Re-transfer/re-checkout the file in binary mode and compare hashes against the source.","Isolate the bad asset by loading files individually until the loader names the culprit path."],"exampleFix":"// before — a KTX2 v1 file renamed to .ktx2\nlet image = server.load(\"noise.ktx2\"); // InvalidData(\"Failed to parse ktx2 file: ...\")\n\n// after — convert to a real KTX2 v2 with toktx\n// toktx --bcmp noise.png -o noise.ktx2\nlet image = server.load(\"noise.ktx2\");","handlingStrategy":"try-catch","validationCode":"// cheap container sniff before loading\nfn looks_like_ktx2(bytes: &[u8]) -> bool {\n    bytes.starts_with(b\"\\xABKTX 20\\xBB\\r\\n\\x1A\\n\")\n}\nfn looks_like_dds(bytes: &[u8]) -> bool {\n    bytes.starts_with(b\"DDS \")\n}","typeGuard":null,"tryCatchPattern":"match Image::from_buffer(&bytes, ImageType::Format(ImageFormat::Ktx2), formats, true, sampler, usage) {\n    Err(TextureError::InvalidData(msg)) => {\n        error!(\"malformed container: {msg}\"); // regenerate with toktx/texconv/basisu\n        use_placeholder()\n    }\n    result => result,\n}","preventionTips":["Generate all compressed containers with one pinned, known-good tool version.","Add a CI asset smoke test that loads every .ktx2/.dds/.basis file.","Block line-ending normalization for binary assets in .gitattributes."],"tags":["bevy","ktx2","dds","basis","corrupt-file","rust"],"backgroundTag":"corrupt-image-file","analyzedSha":"221e52ae323febfd399bd7d067918fc43648cfb3","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}