egametang/ET · error · Exception

exceed max file size

Error message

exceed max file size

What it means

Thrown by BundleFileReader.ReadFiles when a single file entry inside a Unity asset bundle reports a decompressed size >= int.MaxValue (~2 GiB). The reader allocates a managed MemoryStream whose capacity parameter is an int, so any entry at or above 2 GiB cannot be represented and the method aborts rather than silently truncating. The commented-out block beneath the throw shows an alternative using MemoryMappedFile that was disabled, confirming the hard limit is architectural, not accidental.

Source

Thrown at Packages/cn.etetet.hybridclr/Scripts/Editor/Share/3rds/UnityFS/BundleFileReader.cs:185

            {
                blocksStream = new MemoryStream((int)uncompressedSizeSum);
            }
            return blocksStream;
        }

        public void ReadFiles(Stream blocksStream)
        {
            fileList = new StreamFile[m_DirectoryInfo.Length];
            for (int i = 0; i < m_DirectoryInfo.Length; i++)
            {
                var node = m_DirectoryInfo[i];
                var file = new StreamFile();
                fileList[i] = file;
                file.path = node.path;
                file.fileName = Path.GetFileName(node.path);
                if (node.size >= int.MaxValue)
                {
                    throw new Exception($"exceed max file size");
                    /*var memoryMappedFile = MemoryMappedFile.CreateNew(null, entryinfo_size);
                    file.stream = memoryMappedFile.CreateViewStream();*/
                    //var extractPath = path + "_unpacked" + Path.DirectorySeparatorChar;
                    //Directory.CreateDirectory(extractPath);
                    //file.stream = new FileStream(extractPath + file.fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                }
                file.stream = new MemoryStream((int)node.size);
                blocksStream.Position = node.offset;
                blocksStream.CopyTo(file.stream, node.size);
                file.stream.Position = 0;
            }
        }

        private void ReadBlocks(EndianBinaryReader reader, Stream blocksStream)
        {
            foreach (var blockInfo in m_BlocksInfo)
            {
                var compressedSize = (int)blockInfo.compressedSize;

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Split the oversized asset into multiple smaller bundles so no single entry exceeds 2 GiB.
  2. Verify the integrity of the bundle file — if the size looks wrong, the directory table may be corrupt; re-export the bundle from source.
  3. If you control the reader and must support large files, re-enable the commented-out MemoryMappedFile path or switch to a FileStream-based extraction to disk instead of MemoryStream.
  4. Audit the bundle's directory info before calling ReadFiles to reject or warn on oversized entries early.

Example fix

// before
file.stream = new MemoryStream((int)node.size);

// after — write large entries to disk instead of memory
if (node.size >= int.MaxValue)
{
    var extractPath = Path.Combine(Path.GetTempPath(), file.fileName);
    file.stream = new FileStream(extractPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
}
else
{
    file.stream = new MemoryStream((int)node.size);
}
Defensive patterns

Strategy: validation

Validate before calling

long maxSize = int.MaxValue - 1; // ~2 GiB limit for MemoryStream capacity
foreach (var node in m_DirectoryInfo)
{
    if (node.size >= maxSize)
    {
        Debug.LogError($"File '{node.path}' size {node.size} exceeds the {maxSize} byte MemoryStream limit.");
        // split the bundle or switch to FileStream extraction
    }
}

Try / catch

try
{
    bundleFile.ReadFiles(blocksStream);
}
catch (Exception ex) when (ex.Message.Contains("exceed max file size"))
{
    Debug.LogError($"Bundle contains a file >= 2 GiB which cannot be loaded into memory. " +
        $"Split the asset or use a disk-based reader. Path: {bundlePath}");
}

Prevention

When it happens

Trigger: Calling ReadFiles on a BundleFile whose m_DirectoryInfo[i].size field (read from the bundle's directory table) is >= 2,147,483,647 bytes. This happens when the bundle contains one very large uncompressed asset (e.g. a huge texture, video, or raw binary) or when the directory metadata is corrupt and reports an inflated size.

Common situations: Bundling large video or audio assets that exceed 2 GiB after decompression; corrupt or tampered bundle files with garbled directory entries; bundles generated by tooling that does not chunk large assets; attempting to unpack a deliberately crafted or malformed bundle during reverse-engineering.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/9ffbd21bb6e2ad5c. Report an issue: GitHub.