{"record":{"id":"2ce78029f0fc33b2","repo":"SixLabors/ImageSharp","slug":"errormessage-tgathrowhelper","errorCode":null,"errorMessage":"{errorMessage}","messagePattern":"\\{errorMessage\\}","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Tga/TgaThrowHelper.cs","lineNumber":9,"sourceCode":"// Copyright (c) Six Labors.\n// Licensed under the Six Labors Split License.\n\nnamespace SixLabors.ImageSharp.Formats.Tga;\n\ninternal static class TgaThrowHelper\n{\n    public static void ThrowInvalidImageContentException(string errorMessage)\n        => throw new InvalidImageContentException(errorMessage);\n\n    public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)\n        => throw new InvalidImageContentException(errorMessage, innerException);\n\n    public static void ThrowNotSupportedException(string errorMessage)\n        => throw new NotSupportedException(errorMessage);\n}\n","sourceCodeStart":1,"sourceCodeEnd":17,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Tga/TgaThrowHelper.cs#L1-L17","documentation":"TgaThrowHelper.ThrowInvalidImageContentException(string) throws InvalidImageContentException with a caller-provided message. It is the TGA decoder's standard guard for content that violates TGA expectations: non-positive dimensions, missing/oversized color maps, unsupported combinations of image type and pixel depth, and per-scanline length mismatches. The exact reason is always carried in the message string.","triggerScenarios":"Calling by TgaDecoderCore when header checks fail, e.g. width or height <= 0 (line 77), missing color-map length (line 87), unsupported type/depth combinations, or scanline data not matching the declared geometry (lines ~407-921).","commonSituations":"Zero-sized TGA files produced by crashed tools; color-mapped images with truncated palettes; TGA variants with unexpected pixel depths (e.g. unsupported bit counts); corrupted downloads.","solutions":["Read the exception message for the specific violation (dimensions, color map, depth) and inspect the 18-byte TGA header accordingly.","Re-export or convert the file from its source application into a standard TGA or PNG.","Pre-check file size against header-declared dimensions before decoding large/old files.","Catch InvalidImageContentException and route the file to a repair/conversion path."],"exampleFix":"// before\nusing var image = Image.Load(\"art.tga\");\n// after\ntry\n{\n    using var image = Image.Load(\"art.tga\");\n}\ncatch (InvalidImageContentException ex)\n{\n    Console.WriteLine($\"TGA content invalid: {ex.Message}\");\n}","handlingStrategy":"validation","validationCode":"// Basic TGA header triage before decode.\nbyte[] h = new byte[18];\nusing (var fs = File.OpenRead(path)) if (fs.Read(h, 0, 18) != 18) throw new InvalidDataException(\"Too short.\");\nbyte idLen = h[0], cmLen = h[5];\nint w = h[12] | (h[13] << 8), ht = h[14] | (h[15] << 8);\nif (w == 0 || ht == 0) throw new InvalidDataException(\"TGA has zero dimensions.\");\nif (h[1] == 1 && cmLen == 0) throw new InvalidDataException(\"Color-mapped TGA without color map length.\");","typeGuard":null,"tryCatchPattern":"try { using var img = Image.Load(path); }\ncatch (InvalidImageContentException ex) { Console.WriteLine($\"Reject TGA: {ex.Message}\"); }","preventionTips":["Always read the exception message — it states the exact violated TGA expectation.","Convert odd TGA variants to PNG upstream.","Reject zero-dimension headers at ingest.","Fuzz-test your ingest path if untrusted images are common."],"tags":["tga","image-decoding","invalid-content"],"backgroundTag":"schema-validation-failed","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}