{"record":{"id":"0251b1d8d8b28094","repo":"HMCL-dev/HMCL","slug":"indexed-images-colour-type-d-cannot-have-bitdep","errorCode":null,"errorMessage":"Indexed images (colour type %d) cannot have bitdepth > 8 (bit depth %d). See http://www.w3.org/TR/2003/REC-PNG-20031110/#table111 .","messagePattern":"Indexed images \\(colour type (.+?)\\) cannot have bitdepth > 8 \\(bit depth (.+?)\\)\\. See http://www\\.w3\\.org/TR/2003/REC-PNG-20031110/#table111 \\.","errorType":"exception","errorClass":"PngIntegrityException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/ui/image/apng/chunks/PngHeader.java","lineNumber":197,"sourceCode":"        }\n    }\n\n    public static void checkHeaderParameters(int width, int height, byte bitDepth, PngColourType colourType, byte compressionMethod, byte filterMethod, byte interlaceMethod) throws PngException {\n\n        switch (bitDepth) {\n            case 1:\n            case 2:\n            case 4:\n            case 8:\n            case 16:\n                break; // all fine\n            default:\n                throw new PngIntegrityException(\"Invalid bit depth \" + bitDepth);\n        }\n\n        // thanks to pypng\n        if (colourType.isIndexed() && bitDepth > 8) {\n            throw new PngIntegrityException(String.format(\n                    \"Indexed images (colour type %d) cannot have bitdepth > 8 (bit depth %d).\" +\n                            \" See http://www.w3.org/TR/2003/REC-PNG-20031110/#table111 .\", colourType.code, bitDepth));\n        }\n\n        if (bitDepth < 8 && !colourType.supportsSubByteDepth()) {\n            throw new PngIntegrityException(String.format(\n                    \"Illegal combination of bit depth (%d) and colour type (%d).\" +\n                            \" See http://www.w3.org/TR/2003/REC-PNG-20031110/#table111 .\", colourType.code, bitDepth));\n        }\n\n        if (interlaceMethod != 0) {\n            throw new PngFeatureException(\"Interlaced images are not yet supported\");\n        }\n    }\n\n    public static PngHeader from(DataInput dis) throws IOException, PngException {\n        int width = dis.readInt();\n        int height = dis.readInt();","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/ui/image/apng/chunks/PngHeader.java#L179-L215","documentation":"This guard enforces the PNG spec rule that indexed-colour (palette) images may only use bit depths up to 8. When checkHeaderParameters sees an indexed colour type whose declared bitDepth is 16, the IHDR combination is illegal per the PNG specification (Table 11, referenced in the message), so the header is rejected as an integrity error.","triggerScenarios":"An IHDR with colour type 3 (indexed) and bit depth 16, typically from a corrupt header or a broken encoder.","commonSituations":"Corrupted PNGs, files produced by non-conformant tools, hand-crafted header bytes in test suites.","solutions":["Fix the source image: re-encode it with a compliant tool so indexed images use bit depth <= 8.","If you control generation, emit colour type 3 only with bit depths 1, 2, 4 or 8.","Catch PngIntegrityException and reject the file as non-conformant."],"exampleFix":"// before: accepting any header\nPngHeader.from(dis);\n// after: pre-check\nif (colourType.code == 3 && bitDepth > 8) {\n    throw new IllegalArgumentException(\"indexed PNG must have bitDepth <= 8\");\n}\nPngHeader.from(dis);","handlingStrategy":"validation","validationCode":"if (colourType == 3 && bitDepth > 8) throw new IllegalArgumentException(\"indexed PNG bitDepth must be <= 8\");","typeGuard":null,"tryCatchPattern":"try { header = PngHeader.from(dis); } catch (PngIntegrityException e) { showUnsupportedImageMessage(); }","preventionTips":["Only produce indexed PNGs with depths 1/2/4/8.","Validate header combos against PNG spec table 11.1 before decode.","Reject non-conformant files early in ingestion.","Keep encoder libraries up to date."],"tags":["png","image-decoding","validation","colour-type"],"backgroundTag":"invalid-enum-value","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}