{"record":{"id":"3df9dbccd1fc7934","repo":"louthy/language-ext","slug":"s","errorCode":null,"errorMessage":"s","messagePattern":"s","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/DataTypes/StringM/StringM.Trait.cs","lineNumber":72,"sourceCode":"    \n    int IComparable<SELF>.CompareTo(SELF? rhs) =>\n        rhs is null \n            ? 1 \n            : SELF.Compare((SELF)this, rhs);\n\n    static SELF IParsable<SELF>.Parse(string s, IFormatProvider? provider) => \n        SELF.FromUnsafe(s);\n\n    static bool IParsable<SELF>.TryParse(string? s, IFormatProvider? provider, out SELF result)\n    {\n        result = SELF.FromUnsafe(s ?? \"\");\n        return s != null;\n    }\n\n    static SELF ISpanParsable<SELF>.Parse(ReadOnlySpan<char> s, IFormatProvider? provider)\n    {\n        // magic number from System.String\n        if (s.Length > 1073741791) throw new ArgumentException(nameof(s));\n        return SELF.FromUnsafe(s.ToString());\n    }\n\n    static bool ISpanParsable<SELF>.TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out SELF result)\n    {\n        if (s.Length <= 1073741791) // magic number from System.String\n        {\n            result = SELF.FromUnsafe(s.ToString());\n            return true;\n        }\n        result = default!;\n        return false;\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":87,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/DataTypes/StringM/StringM.Trait.cs#L54-L87","documentation":"StringM's ISpanParsable<SELF>.Parse checks the span length against System.String's maximum length (1,073,741,791 chars) and throws ArgumentException (with the parameter name \"s\" as the message) when exceeded, before converting via SELF.FromUnsafe.","triggerScenarios":"Implicitly invoking Parse (via ISpanParsable/IParsable APIs like int.Parse-style parsing, span conversions, or parsing pipelines) with a ReadOnlySpan<char> longer than 1,073,741,791 characters.","commonSituations":"Parsing enormous in-memory text blobs or memory-mapped files as strings; upstream data-size limits missing so oversized spans reach Parse; angle of attack — pathological inputs in deserialization paths.","solutions":["Check s.Length <= 1073741791 before invoking any parse that funnels into StringM.Parse.","Reject or stream-process oversized inputs upstream instead of converting them to strings.","If parsing is genuinely needed, split the input into chunks within the limit."],"exampleFix":"// before\nvar value = SELF.Parse(span, provider); // throws for giant spans\n\n// after\nif (span.Length > 1073741791) throw new ArgumentException(\"input too large to parse\", nameof(span));\nvar value = SELF.Parse(span, provider);","handlingStrategy":"validation","validationCode":"// before parsing\nconst int MaxStringLen = 1073741791;\nif (s.Length > MaxStringLen) throw new ArgumentException(\"input exceeds max string length\", nameof(s));","typeGuard":"static bool Parseable(ReadOnlySpan<char> s) => s.Length <= 1073741791;","tryCatchPattern":"try { var v = SELF.Parse(span, provider); }\ncatch (ArgumentException) { /* input exceeds System.String max length — reject input */ }","preventionTips":["Enforce an input-size cap well below 1,073,741,791 chars before parsing.","Stream or chunk very large inputs instead of materializing them as strings.","Treat oversized inputs as data-validation failures at the API boundary."],"tags":["csharp","languageext","parsing","strings","ispanparsable"],"backgroundTag":"invalid-argument-value","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}