{"record":{"id":"ce13c1570541cd74","repo":"tursodatabase/turso","slug":"invalid-value-origin-for-enum-type-seekorigin","errorCode":null,"errorMessage":"Invalid value {origin} for enum type {SeekOrigin}.","messagePattern":"Invalid value (.+?) for enum type (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs","lineNumber":77,"sourceCode":"    {\n        Persist();\n    }\n\n    public override int Read(byte[] buffer, int offset, int count)\n    {\n        ValidateBuffer(buffer, offset, count);\n        return GetStream().Read(buffer, offset, count);\n    }\n\n    public override long Seek(long offset, SeekOrigin origin)\n    {\n        var stream = GetStream();\n        var position = origin switch\n        {\n            SeekOrigin.Begin => offset,\n            SeekOrigin.Current => stream.Position + offset,\n            SeekOrigin.End => stream.Length + offset,\n            _ => throw new ArgumentException(Properties.Resources.InvalidEnumValue(typeof(SeekOrigin), origin), nameof(origin))\n        };\n        if (position < 0)\n            throw new IOException(Properties.Resources.SeekBeforeBegin);\n\n        stream.Position = position;\n        return position;\n    }\n\n    public override void SetLength(long value)\n    {\n        throw new NotSupportedException(Properties.Resources.ResizeNotSupported);\n    }\n\n    public override void Write(byte[] buffer, int offset, int count)\n    {\n        if (_readOnly)\n            throw new NotSupportedException(Properties.Resources.WriteNotSupported);\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs#L59-L95","documentation":"SqliteBlob.Seek resolves the target position with an exhaustive switch over SeekOrigin; any value outside Begin/Current/End falls into the discard arm and throws ArgumentException. SeekOrigin is a plain enum, so an out-of-range integer can be cast to it; the guard rejects such values instead of silently computing an undefined position.","triggerScenarios":"Casting a raw int/byte (protocol tag, serialized value) to SeekOrigin without validation, e.g. (SeekOrigin)99; arithmetic on enum values that leaves the defined range; forwarding a user- or config-supplied origin into Seek.","commonSituations":"Binary protocol parsers that encode seek-origin as a numeric code; ports from languages with open enums; fuzz/randomized unit tests feeding arbitrary origins; data-driven stream wrappers forwarding external input.","solutions":["Validate at your boundary before calling: if (!Enum.IsDefined(typeof(SeekOrigin), origin)) reject the input.","Map numeric codes to SeekOrigin explicitly (switch on the int) instead of blind-casting.","Use Enum.TryParse<SeekOrigin>() when the value arrives as text."],"exampleFix":"// before\nvar origin = (SeekOrigin)codeFromWire;   // codeFromWire == 7\nblob.Seek(0, origin);                    // throws: Invalid value 7 for enum type SeekOrigin\n\n// after\nif (!Enum.IsDefined(typeof(SeekOrigin), (SeekOrigin)codeFromWire))\n    throw new ArgumentOutOfRangeException(nameof(codeFromWire));\nblob.Seek(0, (SeekOrigin)codeFromWire);","handlingStrategy":"validation","validationCode":"static bool IsValidSeekOrigin(int raw) => raw is >= 0 and <= 2; // Begin, Current, End\n\nif (IsValidSeekOrigin(codeFromWire))\n    blob.Seek(offset, (SeekOrigin)codeFromWire);","typeGuard":"static SeekOrigin? ToSeekOrigin(int raw) => raw switch {\n    0 => SeekOrigin.Begin,\n    1 => SeekOrigin.Current,\n    2 => SeekOrigin.End,\n    _ => null, // caller rejects null\n};","tryCatchPattern":null,"preventionTips":["Never blind-cast ints to enums at trust boundaries; validate with Enum.IsDefined.","Encode/decode SeekOrigin through an explicit mapping table.","Reject unknown wire values with ArgumentOutOfRangeException at the protocol layer."],"tags":["dotnet","stream","seek","enum-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}