{"record":{"id":"94a309803b12dc36","repo":"Tencent/matrix","slug":"dataerrorexception","errorCode":null,"errorMessage":"DataErrorException","messagePattern":"DataErrorException","errorType":"exception","errorClass":"DataErrorException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-backtrace/src/main/cpp/external/libunwindstack/deps/liblzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs","lineNumber":337,"sourceCode":"\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\trep0 = posSlot;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tthrow new DataErrorException();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\n\t\t\t\t\t\tnowPos64 += len;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tm_OutWindow.Flush();\n\t\t\tm_OutWindow.ReleaseStream();\n\t\t\tm_RangeDecoder.ReleaseStream();\n\t\t}\n\n\t\tpublic void SetDecoderProperties(byte[] properties)\n\t\t{\n\t\t\tif (properties.Length < 5)\n\t\t\t\tthrow new InvalidParamException();\n\t\t\tint lc = properties[0] % 9;\n\t\t\tint remainder = properties[0] / 9;\n\t\t\tint lp = remainder % 5;","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-backtrace/src/main/cpp/external/libunwindstack/deps/liblzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs#L319-L355","documentation":"The 7-Zip LZMA C# decoder throws DataErrorException when the compressed stream is corrupt: during the match copy phase the computed distance rep0 exceeds the trained window size plus output produced so far, or exceeds the configured dictionary size check, meaning the decoder was asked to copy from data that was never written — an invalid distance in the LZMA stream.","triggerScenarios":"Decoding a truncated, corrupted, or not-really-LZMA byte stream whose match distance bits decode to a value larger than the dictionary/output window; called via Decoder.Code from Main2 or LzmaBenchmark.","commonSituations":"Feeding the decoder a file that was compressed with different properties, passing a partially downloaded/corrupted blob, or passing uncompressed data to the LZMA decoder.","solutions":["Verify the input bytes are a complete, valid LZMA stream (re-compress the source to confirm)","Ensure SetDecoderProperties is called with the exact 5 property bytes used at compression time (wrong dictionary size can make valid distances appear out of range)","Catch DataErrorException in the caller and treat it as corrupted-input, surfacing a checksum/download retry","Check stream integrity (CRC/length) before decoding to detect truncation early"],"exampleFix":"// before\nnew Lzma.Decoder().Code(inStream, outStream, inSize, outSize, null);\n\n// after\ntry {\n    new Lzma.Decoder().Code(inStream, outStream, inSize, outSize, null);\n} catch (Lzma.DataErrorException) {\n    throw new IOException(\"LZMA stream is corrupted or truncated\");\n}","handlingStrategy":"try-catch","validationCode":"// before decoding\nif (compressedData == null || compressedData.Length == 0)\n    throw new IOException(\"Empty LZMA input\");\n// verify stored size/CRC matches before decoding","typeGuard":null,"tryCatchPattern":"// C#\ntry {\n    decoder.Code(inStream, outStream, inSize, outSize, null);\n} catch (DataErrorException ex) {\n    // treat as corrupted/truncated input: log, verify source, retry download\n    throw new InvalidDataException(\"LZMA stream corrupt\", ex);\n}","preventionTips":["Always decode with the same 5-byte properties the encoder used","Store/verify a checksum alongside compressed data to detect corruption early","Wrap Code() in try-catch and treat DataErrorException as corrupted input","Validate downloads complete (content-length) before decompressing"],"tags":["csharp","compression","lzma","corrupt-data"],"backgroundTag":"checksum-mismatch","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}