{"record":{"id":"75145cb83c60156a","repo":"LorisYounger/VPet","slug":"invalid-png-apng-signature","errorCode":null,"errorMessage":"Invalid PNG/APNG signature.","messagePattern":"Invalid PNG/APNG signature\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"VPet-Simulator.Core/Graph/APNGAnimation.cs","lineNumber":249,"sourceCode":"                            canvas.DrawBitmap(previousCanvas, 0, 0);\n                        }\n                        break;\n                }\n            }\n\n            using var image = SKImage.FromBitmap(combinedBitmap);\n            using var data = image.Encode(SKEncodedImageFormat.Png, 100);\n            using var stream = File.Open(SpriteSheetPath, FileMode.Create, FileAccess.Write, FileShare.Read);\n            data.SaveTo(stream);\n        }\n\n        private static ParsedApng ParseApng(string path)\n        {\n            using var stream = File.OpenRead(path);\n            using var reader = new BinaryReader(stream);\n            var signature = reader.ReadBytes(8);\n            if (signature.Length != 8 || !MatchesSignature(signature))\n                throw new InvalidDataException(\"Invalid PNG/APNG signature.\");\n\n            var result = new ParsedApng();\n            ApngFrameData? currentFrame = null;\n            bool imageDataStarted = false;\n\n            while (stream.Position < stream.Length)\n            {\n                uint length = ReadUInt32BigEndian(reader);\n                string type = Encoding.ASCII.GetString(reader.ReadBytes(4));\n                byte[] data = reader.ReadBytes((int)length);\n                ReadUInt32BigEndian(reader);\n\n                switch (type)\n                {\n                    case \"IHDR\":\n                        result.IhdrTemplate = data;\n                        result.CanvasWidth = (int)ReadUInt32BigEndian(data, 0);\n                        result.CanvasHeight = (int)ReadUInt32BigEndian(data, 4);","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/LorisYounger/VPet/blob/ffb9cc2a856244a0f91aa5ecf10d097bcdd4954f/VPet-Simulator.Core/Graph/APNGAnimation.cs#L231-L267","documentation":"Thrown by ParseApng while opening an APNG file for frame parsing: the file's first bytes are read and compared against the canonical PNG signature (137 80 78 71 13 10 26 10). This is a generic validation guard, and the failing input is the sprite/animation file at `path` — typically a file that is not a PNG at all (a JPEG/WebP or other format renamed to .png, a truncated download, or a zero-byte/corrupted file). It signals that APNG frame extraction cannot proceed and the animation cannot be decoded as a PNG/APNG.","triggerScenarios":"Path points to a JPEG/GIF/WebP/BMP, an HTML error page saved as .png, or a zero-byte file; passed to the APNGAnimation public constructor.","commonSituations":"Extension renamed manually; CDN/download returned an error page; placeholder file; asset pipeline saved wrong format with .png extension.","solutions":["Point Path at a genuine PNG/APNG file.","Verify the first 8 bytes are the PNG signature before loading.","Re-export the image as PNG.","Re-download the asset if the file is an HTML/error-page stub."],"exampleFix":"// before\nnew APNGAnimation(imagePath); // actually a JPEG\n// after\nvar bytes = new byte[8];\nusing (var fs = File.OpenRead(imagePath)) fs.Read(bytes, 0, 8);\nbool isPng = bytes.SequenceEqual(new byte[]{137,80,78,71,13,10,26,10});\nif (isPng) new APNGAnimation(imagePath);","handlingStrategy":"validation","validationCode":"static bool IsPng(string p) { var b = new byte[8]; using var fs = File.OpenRead(p); return fs.Read(b,0,8)==8 && b.AsSpan().SequenceEqual(stackalloc byte[]{137,80,78,71,13,10,26,10}); }","typeGuard":"bool IsPngFile(string path) => File.Exists(path) && IsPng(path);","tryCatchPattern":"try { var anim = new APNGAnimation(path); } catch (InvalidDataException ex) when (ex.Message.Contains(\"signature\")) { Log.Warn($\"{path} is not a PNG\"); }","preventionTips":["Check magic bytes before loading any image file","Never rename extensions manually; re-export with a converter","Validate downloaded assets (size + signature) before install"],"tags":["png","format-validation","file-io"],"backgroundTag":"invalid-argument-format","analyzedSha":"ffb9cc2a856244a0f91aa5ecf10d097bcdd4954f","analyzedAt":"2026-09-15T21:21:10.398Z","contentChangedAt":"2026-09-15T21:21:10.398Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}