{"record":{"id":"9ffbd21bb6e2ad5c","repo":"egametang/ET","slug":"exceed-max-file-size","errorCode":null,"errorMessage":"exceed max file size","messagePattern":"exceed max file size","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.hybridclr/Scripts/Editor/Share/3rds/UnityFS/BundleFileReader.cs","lineNumber":185,"sourceCode":"            {\n                blocksStream = new MemoryStream((int)uncompressedSizeSum);\n            }\n            return blocksStream;\n        }\n\n        public void ReadFiles(Stream blocksStream)\n        {\n            fileList = new StreamFile[m_DirectoryInfo.Length];\n            for (int i = 0; i < m_DirectoryInfo.Length; i++)\n            {\n                var node = m_DirectoryInfo[i];\n                var file = new StreamFile();\n                fileList[i] = file;\n                file.path = node.path;\n                file.fileName = Path.GetFileName(node.path);\n                if (node.size >= int.MaxValue)\n                {\n                    throw new Exception($\"exceed max file size\");\n                    /*var memoryMappedFile = MemoryMappedFile.CreateNew(null, entryinfo_size);\n                    file.stream = memoryMappedFile.CreateViewStream();*/\n                    //var extractPath = path + \"_unpacked\" + Path.DirectorySeparatorChar;\n                    //Directory.CreateDirectory(extractPath);\n                    //file.stream = new FileStream(extractPath + file.fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);\n                }\n                file.stream = new MemoryStream((int)node.size);\n                blocksStream.Position = node.offset;\n                blocksStream.CopyTo(file.stream, node.size);\n                file.stream.Position = 0;\n            }\n        }\n\n        private void ReadBlocks(EndianBinaryReader reader, Stream blocksStream)\n        {\n            foreach (var blockInfo in m_BlocksInfo)\n            {\n                var compressedSize = (int)blockInfo.compressedSize;","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.hybridclr/Scripts/Editor/Share/3rds/UnityFS/BundleFileReader.cs#L167-L203","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Split the oversized asset into multiple smaller bundles so no single entry exceeds 2 GiB.","Verify the integrity of the bundle file — if the size looks wrong, the directory table may be corrupt; re-export the bundle from source.","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.","Audit the bundle's directory info before calling ReadFiles to reject or warn on oversized entries early."],"exampleFix":"// before\nfile.stream = new MemoryStream((int)node.size);\n\n// after — write large entries to disk instead of memory\nif (node.size >= int.MaxValue)\n{\n    var extractPath = Path.Combine(Path.GetTempPath(), file.fileName);\n    file.stream = new FileStream(extractPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);\n}\nelse\n{\n    file.stream = new MemoryStream((int)node.size);\n}","handlingStrategy":"validation","validationCode":"long maxSize = int.MaxValue - 1; // ~2 GiB limit for MemoryStream capacity\nforeach (var node in m_DirectoryInfo)\n{\n    if (node.size >= maxSize)\n    {\n        Debug.LogError($\"File '{node.path}' size {node.size} exceeds the {maxSize} byte MemoryStream limit.\");\n        // split the bundle or switch to FileStream extraction\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    bundleFile.ReadFiles(blocksStream);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"exceed max file size\"))\n{\n    Debug.LogError($\"Bundle contains a file >= 2 GiB which cannot be loaded into memory. \" +\n        $\"Split the asset or use a disk-based reader. Path: {bundlePath}\");\n}","preventionTips":["Keep individual assets within bundles under 2 GiB by splitting large media.","Validate bundle directory entries before calling ReadFiles to catch oversized or corrupt sizes early.","Consider a disk-based extraction path for bundles expected to contain very large assets.","Add bundle size assertions in the build pipeline to catch oversized bundles before distribution."],"tags":["unityfs","asset-bundle","memory","size-limit","file-io"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}