{"record":{"id":"23283811331f9e0d","repo":"nilaoda/N_m3u8DL-RE","slug":"pssh-version-can-only-be-0-or-1","errorCode":null,"errorMessage":"PSSH version can only be 0 or 1","messagePattern":"PSSH version can only be 0 or 1","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE.Parser/Mp4/MP4InitUtil.cs","lineNumber":33,"sourceCode":"        private static readonly byte[] SYSTEM_ID_WIDEVINE = [0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED];\n        private static readonly byte[] SYSTEM_ID_PLAYREADY = [0x9A, 0x04, 0xF0, 0x79, 0x98, 0x40, 0x42, 0x86, 0xAB, 0x92, 0xE6, 0x5B, 0xE0, 0x88, 0x5F, 0x95];\n\n        public static ParsedMP4Info ReadInit(byte[] data)\n        {\n            var info = new ParsedMP4Info();\n\n            // parse init\n            new MP4Parser()\n                .Box(\"moov\", MP4Parser.Children)\n                .Box(\"trak\", MP4Parser.Children)\n                .Box(\"mdia\", MP4Parser.Children)\n                .Box(\"minf\", MP4Parser.Children)\n                .Box(\"stbl\", MP4Parser.Children)\n                .FullBox(\"stsd\", MP4Parser.SampleDescription)\n                .FullBox(\"pssh\", box =>\n                {\n                    if (box.Version is not (0 or 1))\n                        throw new Exception(\"PSSH version can only be 0 or 1\");\n                    var systemId = box.Reader.ReadBytes(16);\n                    if (!SYSTEM_ID_WIDEVINE.SequenceEqual(systemId)) return;\n                    \n                    var dataSize = box.Reader.ReadUInt32();\n                    var psshData = box.Reader.ReadBytes((int)dataSize);\n                    info.PSSH = Convert.ToBase64String(psshData);\n                    if (info.KID != \"00000000000000000000000000000000\") return;\n                    \n                    info.KID = HexUtil.BytesToHex(psshData[2..18]).ToLower();\n                    info.isMultiDRM = true;\n                })\n                .FullBox(\"encv\", MP4Parser.AllData(data => ReadBox(data, info)))\n                .FullBox(\"enca\", MP4Parser.AllData(data => ReadBox(data, info)))\n                .FullBox(\"enct\", MP4Parser.AllData(data => ReadBox(data, info)))\n                .FullBox(\"encs\", MP4Parser.AllData(data => ReadBox(data, info)))\n                .Parse(data, stopOnPartial: true);\n\n            return info;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE.Parser/Mp4/MP4InitUtil.cs#L15-L51","documentation":"While walking the MP4 init segment, the MP4Parser FullBox handler for 'pssh' rejects PSSH boxes whose version is not 0 or 1; only these versions are defined for the Protection System Specific Header box. Any other version byte means a corrupt or nonstandard file.","triggerScenarios":"Calling MP4InitUtil.ReadInit on an MP4 init segment whose moov contains a pssh full box with version other than 0 or 1 (corrupt box, wrong offset parsing, or a nonstandard muxer output).","commonSituations":"Corrupt/truncated DASH or fMP4 init segment, an unusual muxer writing malformed pssh boxes, or feeding a non-fMP4 file into ReadInit.","solutions":["Re-obtain or re-download the init segment — the file is likely corrupt.","Inspect the pssh box with a tool (e.g. Bento4/MP4Box dump) to verify version and contents.","Remux/repackage the content with a standard muxer (ffmpeg/Bento4) so pssh boxes use version 0 or 1.","Catch the exception and skip DRM info extraction rather than aborting if PSSH is not required."],"exampleFix":"// before\nvar info = MP4InitUtil.ReadInit(File.ReadAllBytes(initSegment));\n\n// after\ntry\n{\n    var info = MP4InitUtil.ReadInit(File.ReadAllBytes(initSegment));\n}\ncatch (Exception ex) when (ex.Message.Contains(\"PSSH version\"))\n{\n    Log.Warning(\"Init segment has malformed pssh box; skipping DRM info\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var info = MP4InitUtil.ReadInit(bytes); }\ncatch (Exception ex) when (ex.Message.Contains(\"PSSH version\"))\n{ Log.Warning(\"Malformed pssh box; skipping DRM info\"); }","preventionTips":["Verify init segments come from a trusted, uncorrupted source.","Remux nonstandard content with ffmpeg/Bento4 before parsing.","Treat DRM info extraction as optional so a bad pssh box doesn't abort the pipeline."],"tags":["mp4","drm","pssh","parsing"],"backgroundTag":"invalid-enum-value","analyzedSha":"e113dee70c924ee08dae5460624909b04d84cb76","analyzedAt":"2026-09-13T02:43:21.078Z","contentChangedAt":"2026-09-13T02:43:21.078Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}