egametang/ET · error · IOException
Lz4 decompression error, write {numWrite} bytes but expected
Error message
Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes What it means
BundleFileReader.DecompressBytes (line 110) throws IOException when LZ4Codec.Decode writes a different number of bytes than the declared uncompressedSize. The bundle header advertises an uncompressed size that the LZ4 decoder did not reproduce, indicating the compressed payload is corrupt, truncated, or the size header is wrong.
Source
Thrown at Packages/cn.etetet.hybridclr/Scripts/Editor/Share/3rds/UnityFS/BundleFileReader.cs:110
return compressedBytes;
}
case CompressionType.Lzma:
{
var uncompressedStream = new MemoryStream((int)(uncompressedSize));
using (var compressedStream = new MemoryStream(compressedBytes))
{
ComparessHelper.Decompress7Zip(compressedStream, uncompressedStream, m_Header.compressedBlocksInfoSize, m_Header.uncompressedBlocksInfoSize);
}
return uncompressedStream.ReadAllBytes();
}
case CompressionType.Lz4:
case CompressionType.Lz4HC:
{
var uncompressedBytes = new byte[uncompressedSize];
var numWrite = LZ4Codec.Decode(compressedBytes, 0, compressedBytes.Length, uncompressedBytes, 0, uncompressedBytes.Length, true);
if (numWrite != uncompressedSize)
{
throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes");
}
return uncompressedBytes;
}
default:
throw new IOException($"Unsupported compression type {compressionType}");
}
}
private void ReadMetadata(EndianBinaryReader reader)
{
byte[] compressMetadataBytes = ReadBlocksInfoAndDirectoryMetadataUnCompressedBytes(reader);
MemoryStream metadataStream = new MemoryStream(DecompressBytes((CompressionType)(m_Header.flags & ArchiveFlags.CompressionTypeMask), compressMetadataBytes, m_Header.uncompressedBlocksInfoSize));
using (var blocksInfoReader = new EndianBinaryReader(metadataStream))
{
var uncompressedDataHash = blocksInfoReader.ReadBytes(16);
var blocksInfoCount = blocksInfoReader.ReadInt32();
m_BlocksInfo = new StorageBlock[blocksInfoCount];
for (int i = 0; i < blocksInfoCount; i++)View on GitHub (pinned to 5cab01f7a8)
Solutions
- Re-download/rebuild the offending asset bundle (most common cause is truncation/corruption).
- Verify the bundle's hash/checksum against the build manifest before loading.
- Confirm the LZ4 library version matches the one used to build the bundles.
- If rebuilding, ensure the build pipeline writes the correct uncompressedSize per block.
Defensive patterns
Strategy: try-catch
Try / catch
try { reader.Load(...); }
catch (IOException e) when (e.Message.Contains("Lz4 decompression error"))
{ Log.Error($"corrupt/truncated asset bundle: {e.Message}"); /* re-download or rebuild */ } Prevention
- Verify bundle checksums against the build manifest before loading.
- Re-download truncated bundles.
- Keep the LZ4 codec version in sync with the build toolchain.
When it happens
Trigger: Loading a UnityFS asset bundle whose LZ4/LZ4HC block is truncated, bit-flipped, written by a mismatched LZ4 variant, or whose uncompressedSize in the header disagrees with the real data.
Common situations: Downloading a partially-written/cut-off bundle, disk corruption, a build pipeline that set the wrong uncompressed size, mismatched LZ4 library version between writer and reader, or a bundle produced by a Unity version whose block format changed.
Related errors
- too fig file
- Unsupported compression type {compressionType}
- btenv not found key: {key} {typeof(T).FullName}
- 不能把{value.GetType()}转换为{typeof (T)}
- condition root child count error: {node.Children.Count}
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/0baef3b4158b356d.
Report an issue: GitHub.