{"record":{"id":"43d4e7a3a48e49bd","repo":"egametang/ET","slug":"invalid-level-level-expected-level-1-or-le","errorCode":null,"errorMessage":"invalid level: {level} (expected: {LEVEL_1} or {LEVEL_2})","messagePattern":"invalid level: (.+?) \\(expected: (.+?) or (.+?)\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Core/Compression/FastLZ.cs","lineNumber":517,"sourceCode":"            return op;\n        }\n\n        /**\n     * Decompress a block of compressed data and returns the size of the decompressed block.\n     * If error occurs, e.g. the compressed data is corrupted or the output buffer is not large\n     * enough, then 0 (zero) will be returned instead.\n     *\n     * Decompression is memory safe and guaranteed not to write the output buffer\n     * more than what is specified in outLength.\n     */\n        public static int Decompress(byte[] input, int inOffset, int inLength,\n            byte[] output, int outOffset, int outLength)\n        {\n            //int level = ((*(const flzuint8*)input) >> 5) + 1;\n            int level = (input[inOffset] >> 5) + 1;\n            if (level != LEVEL_1 && level != LEVEL_2)\n            {\n                throw new Exception($\"invalid level: {level} (expected: {LEVEL_1} or {LEVEL_2})\");\n            }\n\n            // const flzuint8* ip = (const flzuint8*) input;\n            int ip = 0;\n            // flzuint8* op = (flzuint8*) output;\n            int op = 0;\n            // flzuint32 ctrl = (*ip++) & 31;\n            long ctrl = input[inOffset + ip++] & 31;\n\n            int loop = 1;\n            do\n            {\n                //  const flzuint8* refs = op;\n                int refs = op;\n                // flzuint32 len = ctrl >> 5;\n                long len = ctrl >> 5;\n                // flzuint32 ofs = (ctrl & 31) << 8;\n                long ofs = (ctrl & 31) << 8;","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Core/Compression/FastLZ.cs#L499-L535","documentation":"FastLZ.Decompress reads a 3-bit compression level from the first byte of the input (bits 5-7, plus 1). The only valid levels are LEVEL_1 and LEVEL_2. If the derived level is neither, the input is not a valid FastLZ-compressed block — it is corrupted, truncated, or produced by a different algorithm/version.","triggerScenarios":"Passing a byte array that was not compressed by FastLZ; passing data compressed by FastLZ level 2 to a reader expecting level 1 (only if the header byte is invalid); a truncated or bit-flipped compressed stream whose first byte is wrong; using the wrong offset so the header byte read is not the FastLZ header.","commonSituations":"Corrupted cached navmesh/voxel data on disk; a version change in the compression format; reading past the wrong offset; data produced by a different LZ codec (LZ4, zlib) being fed to FastLZ.Decompress.","solutions":["Verify the data source: confirm it was produced by FastLZ.Compress and not another compressor.","Check inOffset points to the true start of the FastLZ block (not mid-buffer).","If data is from a cache file, clear/regenerate the cache to rule out corruption.","Add a length/header sanity check on input before calling Decompress."],"exampleFix":"// before\nFastLZ.Decompress(data, 0, data.Length, outBuf, 0, outBuf.Length);\n\n// after — validate first byte before decompressing\nint lvl = (data[0] >> 5) + 1;\nif (lvl != FastLZ.LEVEL_1 && lvl != FastLZ.LEVEL_2)\n{\n    throw new InvalidOperationException(\"input is not FastLZ data\");\n}\nFastLZ.Decompress(data, 0, data.Length, outBuf, 0, outBuf.Length);","handlingStrategy":"validation","validationCode":"int lvl = (input[inOffset] >> 5) + 1;\nif (lvl != FastLZ.LEVEL_1 && lvl != FastLZ.LEVEL_2) throw new InvalidOperationException(\"not FastLZ data\");","typeGuard":null,"tryCatchPattern":"try { FastLZ.Decompress(input, inOffset, inLength, output, outOffset, outLength); }\ncatch (Exception ex) { Log.Error($\"FastLZ decompress failed, data may be corrupt: {ex}\"); /* regenerate cache */ }","preventionTips":["Validate the header byte before decompressing.","Confirm input was produced by FastLZ.Compress.","Clear and regenerate compressed caches after version upgrades."],"tags":["recast","compression","fastlz","data-integrity"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}