{"record":{"id":"a994836a3ef463c3","repo":"stride3d/stride","slug":"unexpected-end-of-stream","errorCode":null,"errorMessage":"Unexpected end of stream","messagePattern":"Unexpected end of stream","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs","lineNumber":169,"sourceCode":"        => new($\"Operation '{operationName}' is not supported\");\n\n    /// <summary>Tries to read variable length int.</summary>\n    /// <param name=\"result\">The result.</param>\n    /// <returns><c>true</c> if integer has been read, <c>false</c> if end of stream has been\n    /// encountered at the start of a value.</returns>\n    /// <exception cref=\"IOException\">If end of stream has been encoutered in the middle of a value.</exception>\n    private bool TryReadVarInt(out ulong result)\n    {\n        var buffer = new byte[1];\n        var count = 0;\n        result = 0;\n\n        while (true)\n        {\n            if ((compressedSize != -1 && innerStreamPosition >= compressedSize) || innerStream.Read(buffer, 0, 1) == 0)\n            {\n                if (count == 0) return false;\n                throw new IOException(\"Unexpected end of stream\");\n            }\n            innerStreamPosition++;\n            var b = buffer[0];\n            result += (ulong)(b & 0x7F) << count;\n            count += 7;\n            if ((b & 0x80) == 0 || count >= 64) break;\n        }\n\n        return true;\n    }\n\n    /// <summary>Reads the variable length int. Work with assumption that value is in the stream\n    /// and throws exception if it isn't. If you want to check if value is in the stream\n    /// use <see cref=\"TryReadVarInt\"/> instead.</summary>\n    /// <returns>The value.</returns>\n    /// <exception cref=\"IOException\">The end of the stream was unexpectedly reached.</exception>\n    private ulong ReadVarInt()\n    {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs#L151-L187","documentation":"LZ4Stream.TryReadVarInt reads a LEB128-style varint byte-by-byte from the inner stream. If the stream ends before a complete varint is read (and no partial result has accumulated), it throws IOException('Unexpected end of stream').","triggerScenarios":"Reading a truncated LZ4-compressed stream; calling ReadVarInt at a position past the compressed data; the stream was closed or the file was cut short mid-chunk-header.","commonSituations":"Incomplete downloads of compressed asset files; reading an LZ4 stream produced by a newer/older format version; a writer crashed mid-flush leaving partial data.","solutions":["Verify the source file/stream is complete and untruncated (re-download or regenerate it)","Use TryReadVarInt instead of ReadVarInt when the end of stream is an expected condition","Check that the reader's position starts at a valid chunk boundary (0 or after a fully read chunk)","Confirm writer and reader use the same LZ4Stream format/version"],"exampleFix":"// before\nulong len = stream.ReadVarInt(); // throws on truncation\n// after\nif (!stream.TryReadVarInt(out var len))\n    return false; // graceful end-of-stream","handlingStrategy":"try-catch","validationCode":"if (stream.Position >= stream.Length) return false; // nothing left to read","typeGuard":null,"tryCatchPattern":"try { ok = lz4Stream.TryReadVarInt(out var v); }\ncatch (IOException) { ok = false; /* truncated stream */ }","preventionTips":["Prefer TryReadVarInt when EOF is a valid outcome","Validate compressed files are complete before processing","Keep producer and consumer LZ4Stream versions aligned"],"tags":["io","compression","lz4","truncated-stream"],"backgroundTag":"unexpected-end-of-stream","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}