{"record":{"id":"a7425a3b87184cda","repo":"HMCL-dev/HMCL","slug":"invalid-truecolour-with-alpha-bit-depth-d","errorCode":null,"errorMessage":"Invalid truecolour with alpha bit-depth: %d","messagePattern":"Invalid truecolour with alpha bit-depth: (.+?)","errorType":"exception","errorClass":"PngIntegrityException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/ui/image/apng/argb8888/Argb8888Processors.java","lineNumber":93,"sourceCode":"            case PNG_TRUECOLOUR:\n                switch (header.bitDepth) {\n                    case 8:\n                        return new Truecolour8(bytesPerScanline, bitmap);\n                    case 16:\n                        return new Truecolour16(bytesPerScanline, bitmap);\n                    default:\n                        throw new PngIntegrityException(String.format(\"Invalid truecolour bit-depth: %d\", header.bitDepth)); // TODO: should be in header parse.\n\n                }\n\n            case PNG_TRUECOLOUR_WITH_ALPHA:\n                switch (header.bitDepth) {\n                    case 8:\n                        return new Truecolour8Alpha(bytesPerScanline, bitmap);\n                    case 16:\n                        return new Truecolour16Alpha(bytesPerScanline, bitmap);\n                    default:\n                        throw new PngIntegrityException(String.format(\"Invalid truecolour with alpha bit-depth: %d\", header.bitDepth)); // TODO: should be in header parse.\n\n                }\n\n            default:\n                throw new PngFeatureException(\"ARGB8888 doesn't support PNG mode \" + header.colourType.name());\n        }\n    }\n\n    /**\n     * Transforms 1-, 2-, 4-bit indexed colour source pixels to ARGB8888 pixels.\n     */\n    public static class IndexedColourBits extends Argb8888ScanlineProcessor {\n\n        private int highBit;\n        private int mask;\n        private byte[] shifts;\n\n        public IndexedColourBits(int bytesPerScanline, Argb8888Bitmap bitmap, int highBit, int mask, byte[] shifts) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/ui/image/apng/argb8888/Argb8888Processors.java#L75-L111","documentation":"PngIntegrityException thrown when a truecolour-with-alpha (colour type 6) PNG declares a bit depth other than the legal 8 or 16. The factory only provides Truecolour8Alpha and Truecolour16Alpha, so other depths mean the IHDR is malformed. Like the other bit-depth checks, the TODO indicates it should live in header parsing.","triggerScenarios":"Calling Argb8888Processors.from with a header of colourType PNG_TRUECOLOUR_WITH_ALPHA and bitDepth not in {8,16} — e.g. 1, 2, 4, or corrupted bytes.","commonSituations":"Fuzzed RGBA PNGs; damaged headers from partial downloads; buggy encoders copying depth bytes across colour-type conversions; hand-crafted test binaries.","solutions":["Validate the colour-type/bit-depth pair (type 6 requires 8 or 16) before constructing the processor","Reject the file as structurally invalid at parse time","Re-encode or re-download the image from a trusted source","Catch PngIntegrityException and report a corrupt PNG header"],"exampleFix":"// before\nArgb8888ScanlineProcessor p = Argb8888Processors.from(header, bitmap); // throws for bitDepth=2\n// after\nif (header.colourType == PngColourType.PNG_TRUECOLOUR_WITH_ALPHA\n        && header.bitDepth != 8 && header.bitDepth != 16) {\n    throw new PngIntegrityException(\"IHDR bit depth invalid for truecolour+alpha: \" + header.bitDepth);\n}\nArgb8888ScanlineProcessor p = Argb8888Processors.from(header, bitmap);","handlingStrategy":"validation","validationCode":"if (header.colourType == PngColourType.PNG_TRUECOLOUR_WITH_ALPHA\n        && !(header.bitDepth == 8 || header.bitDepth == 16)) {\n    throw new IllegalArgumentException(\"Invalid truecolour+alpha bit depth: \" + header.bitDepth);\n}","typeGuard":null,"tryCatchPattern":"try {\n    processor = Argb8888Processors.from(header, bitmap);\n} catch (PngIntegrityException e) {\n    throw new IOException(\"Corrupt PNG IHDR (RGBA depth): \" + e.getMessage(), e);\n}","preventionTips":["Enforce the spec's colour-type/bit-depth matrix at parse time","Re-encode images of unknown provenance","Include corrupt-header cases in your decoder test suite"],"tags":["png","bit-depth","alpha","corrupt-file"],"backgroundTag":"invalid-config-value","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}