{"record":{"id":"1c73d154ad45f700","repo":"dotnet/wpf","slug":"0-cannot-start-with-the-reserved-character-range-0x01-0x1f","errorCode":null,"errorMessage":"'{0}' cannot start with the reserved character range 0x01-0x1F.","messagePattern":"'(.+?)' cannot start with the reserved character range 0x01-0x1F\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs","lineNumber":423,"sourceCode":"        {\n            if (testString == null)\n                throw new ArgumentNullException(testStringIdentifier);\n\n            if (testString.Length == 0)\n                throw new ArgumentException(SR.StringEmpty, testStringIdentifier);\n        }\n\n        /// <summary>\n        /// Checks if the given string fits within the range of reserved\n        /// names and throws an ArgumentException if it does.\n        /// The 0x01 through 0x1F characters, serving as the first character of the stream/storage name, \n        /// are reserved for use by OLE. This is a compound file restriction. \n        /// </summary>\n        internal static void CheckStringAgainstReservedName(string nameString,\n            string nameStringIdentifier)\n        {\n            if (IsReservedName(nameString))\n                throw new ArgumentException(\n                    SR.Format(SR.StringCanNotBeReservedName, nameStringIdentifier));\n        }\n\n        /// <summary>\n        /// A certain subset of compound file storage and stream names are \n        /// reserved for use be OLE. These are names that start with a character in the\n        /// range 0x01 to 0x1F.  (1-31)\n        /// This is a compound file restriction\n        /// </summary>\n        internal static bool IsReservedName(string nameString)\n        {\n            CheckStringAgainstNullAndEmpty(nameString, \"nameString\");\n\n            return (nameString[0] >= '\\x0001'\n                    &&\n                    nameString[0] <= '\\x001F');\n        }\n","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/ContainerUtilities.cs#L405-L441","documentation":"CheckStringAgainstReservedName rejects names whose first character is in 0x01-0x1F, a range reserved for OLE compound files. If IsReservedName returns true, it throws ArgumentException (SR.StringCanNotBeReservedName). These control characters cannot be used as the first character of a compound-file storage or stream name.","triggerScenarios":"Calling a compound-file storage/stream creation API with a name string whose first character has code point 0x01-0x1F (control characters).","commonSituations":"Names built from unvalidated user or binary data where control characters slip into the first position, or legacy data containing old control-character prefixes.","solutions":["Strip or reject control characters at the start of the name before calling the API","Sanitize names (e.g. regex removal of [\\x01-\\x1F]) in an input-validation layer","Catch ArgumentException and log/rename the offending name"],"exampleFix":"// before\nCreateStream(userInput);\n// after\nuserInput = Regex.Replace(userInput, \"^[\\x01-\\x1F]+\", \"\");\nCreateStream(userInput);","handlingStrategy":"validation","validationCode":"if (name.Length > 0 && name[0] <= '\\x1F') throw new ArgumentException(\"Name starts with reserved control character\");","typeGuard":"static bool IsNameAllowed(string s) => string.IsNullOrEmpty(s) || s[0] > '\\x1F';","tryCatchPattern":"try { CreateStream(name); } catch (ArgumentException ex) when (ex.Message.Contains(\"reserved\")) { name = SanitizeName(name); CreateStream(name); }","preventionTips":["Sanitize user-supplied names by stripping control characters","Reject binary/legacy data names before use","Add a name whitelist/regex at the input layer"],"tags":["wpf","packaging","reserved-name"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}