{"record":{"id":"9bee9a3104fcc21c","repo":"HMCL-dev/HMCL","slug":"invalid-truecolour-bit-depth-d","errorCode":null,"errorMessage":"Invalid truecolour bit-depth: %d","messagePattern":"Invalid truecolour 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":82,"sourceCode":"                        return new IndexedColourBits(bytesPerScanline, bitmap, 7, 0x01, PngConstants.SHIFTS_1);\n                    case 2:\n                        return new IndexedColourBits(bytesPerScanline, bitmap, 3, 0x03, PngConstants.SHIFTS_2);\n                    case 4:\n                        return new IndexedColourBits(bytesPerScanline, bitmap, 1, 0x0F, PngConstants.SHIFTS_4);\n                    case 8:\n                        return new IndexedColour8(bytesPerScanline, bitmap);\n                    default:\n                        throw new PngIntegrityException(String.format(\"Invalid indexed colour bit-depth: %d\", header.bitDepth)); // TODO: should be in header parse.\n                }\n\n            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    }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/ui/image/apng/argb8888/Argb8888Processors.java#L64-L100","documentation":"PngIntegrityException thrown when a truecolour (colour type 2) PNG declares a bit depth other than the legal 8 or 16. The ARGB8888 factory only implements Truecolour8 and Truecolour16, so any other depth indicates a corrupt IHDR. The TODO notes this belongs in header parsing.","triggerScenarios":"Calling Argb8888Processors.from with a header of colourType PNG_TRUECOLOUR and bitDepth not in {8,16} — e.g. 1, 2, 4, or corrupted values.","commonSituations":"Corrupted or fuzzed PNG headers; hand-rolled encoders emitting wrong depth bytes; files altered by buggy converters; truncated/tampered downloads.","solutions":["Validate that truecolour bit depth is 8 or 16 at header-parse time","Reject the file as corrupt before decoding","Re-obtain or re-encode the image with a compliant tool","Catch PngIntegrityException and surface an invalid-header error"],"exampleFix":"// before: trusting IHDR blindly\nArgb8888ScanlineProcessor p = Argb8888Processors.from(header, bitmap); // throws for bitDepth=4\n// after: early validation\nif (header.colourType == PngColourType.PNG_TRUECOLOUR\n        && header.bitDepth != 8 && header.bitDepth != 16) {\n    throw new PngIntegrityException(\"IHDR bit depth invalid for truecolour: \" + header.bitDepth);\n}\nArgb8888ScanlineProcessor p = Argb8888Processors.from(header, bitmap);","handlingStrategy":"validation","validationCode":"if (header.colourType == PngColourType.PNG_TRUECOLOUR\n        && !(header.bitDepth == 8 || header.bitDepth == 16)) {\n    throw new IllegalArgumentException(\"Invalid truecolour 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 (truecolour depth): \" + e.getMessage(), e);\n}","preventionTips":["Validate the IHDR colour-type/depth matrix before decoding","Verify file integrity (checksums) for images from untrusted sources","Test decoders against deliberately corrupt headers"],"tags":["png","bit-depth","corrupt-file","header-validation"],"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-15T23:17:13.987Z"}