{"record":{"id":"6c3d451c5da129d1","repo":"nilaoda/N_m3u8DL-RE","slug":"mp4-box-names-must-be-4-characters-long","errorCode":null,"errorMessage":"Mp4 box names must be 4 characters long","messagePattern":"Mp4 box names must be 4 characters long","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE.Parser/Mp4/MP4Parser.cs","lineNumber":213,"sourceCode":"                + /* additional 64-bit size field */ (box.Has64BitSize ? 8 : 0)\n                + /* version and flags for a \"full\" box */ (box.Flags != 0 ? 4 : 0);\n        }\n\n        public static string TypeToString(long type)\n        {\n            return Encoding.UTF8.GetString(new byte[]\n            {\n                 (byte)((type >> 24) & 0xff),\n                 (byte)((type >> 16) & 0xff),\n                 (byte)((type >> 8) & 0xff),\n                 (byte)(type & 0xff)\n            });\n        }\n\n        private static int TypeFromString(string name)\n        {\n            if (name.Length != 4)\n                throw new Exception(\"Mp4 box names must be 4 characters long\");\n            var code = 0;\n            foreach (var chr in name) {\n                code = (code << 8) | chr;\n            }\n            return code;\n        }\n\n        public MP4Parser Box(string type, BoxHandler handler)\n        {\n            var typeCode = TypeFromString(type);\n            this.Headers[typeCode] = (int)BoxType.BASIC_BOX;\n            this.BoxDefinitions[typeCode] = handler;\n            return this;\n        }\n\n        public MP4Parser FullBox(string type, BoxHandler handler)\n        {\n            var typeCode = TypeFromString(type);","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE.Parser/Mp4/MP4Parser.cs#L195-L231","documentation":"MP4Parser.TypeFromString converts a 4-character box type name into a packed 32-bit code (each char shifted 8 bits). MP4 box types are defined as exactly four characters, so any other length is rejected with this exception — a programming/API misuse guard.","triggerScenarios":"Passing a string of length other than 4 to MP4Parser box-builder methods (e.g. .Box(\"moovv\", ...) or .Box(\"\", ...)) — the name flows into TypeFromString via the typeCode helper.","commonSituations":"Typo in a box name when writing custom parsing code, truncation of a box name variable, or confusing a multi-character path like \"moov/trak\" with a single box name.","solutions":["Correct the box name passed to .Box()/.FullBox() to exactly 4 ASCII characters (e.g. \"moov\", \"trak\", \"mdia\").","If the target is a nested box, chain separate .Box() calls instead of passing a slash-separated name.","Check for accidental whitespace or truncated string literals in the parser setup code."],"exampleFix":"// before\nparser.Box(\"moov/trak\", MP4Parser.Children);\n\n// after\nparser.Box(\"moov\", MP4Parser.Children)\n      .Box(\"trak\", MP4Parser.Children);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static void EnsureBoxName(string name)\n{\n    if (name?.Length != 4 || name.Any(c => c > 127))\n        throw new ArgumentException($\"MP4 box name must be 4 ASCII chars, got: '{name}'\");\n}","tryCatchPattern":null,"preventionTips":["Always pass literal 4-character box names (\"moov\", \"trak\", \"pssh\") to MP4Parser.Box/FullBox.","Chain nested boxes with separate calls rather than slash-separated strings.","Write a unit test over your parser setup that constructs the parser before running it on real files."],"tags":["mp4","parsing","argument-validation"],"backgroundTag":"invalid-argument-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"}