{"record":{"id":"55afc04ad9a41520","repo":"stride3d/stride","slug":"not-a-valid-zip-entry","errorCode":null,"errorMessage":"Not a valid zip entry.","messagePattern":"Not a valid zip entry\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipFile.cs","lineNumber":456,"sourceCode":"        /// </summary>\n        /// <param name=\"zfe\">\n        /// Entry information of file to extract\n        /// </param>\n        /// <returns>\n        /// Stream to store the uncompressed data\n        /// </returns>\n        /// <remarks>\n        /// Unique compression methods are Store and Deflate\n        /// </remarks>\n        public Stream ReadFile(ZipFileEntry zfe)\n        {\n            // check signature\n            var signature = new byte[4];\n            this.zipFileStream.Seek(zfe.HeaderOffset, SeekOrigin.Begin);\n            this.zipFileStream.Read(signature, 0, 4);\n            if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)\n            {\n                throw new InvalidOperationException(\"Not a valid zip entry.\");\n            }\n\n            // Select input stream for inflating or just reading\n            Stream inStream;\n            switch (zfe.Method)\n            {\n                case Compression.Store:\n                    inStream = this.zipFileStream;\n                    break;\n                case Compression.Deflate:\n                    inStream = new DeflateStream(this.zipFileStream, CompressionMode.Decompress, true);\n                    break;\n                default:\n                    throw new InvalidOperationException(\"Not a valid zip entry.\");\n            }\n\n            this.zipFileStream.Seek(zfe.FileOffset, SeekOrigin.Begin);\n","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.IO/System.IO.Compression.Zip/ZipFile.cs#L438-L474","documentation":"ReadFile seeks to the entry's stored header offset and verifies the local file header signature (0x04034b50, 'PK\\x03\\x04'). A mismatch means the data at that offset is not the expected local entry header, so reading is aborted.","triggerScenarios":"Calling ReadFile with a ZipFileEntry whose HeaderOffset points at wrong/garbage data: the archive was modified after entries were listed, offsets came from a different ZipFile instance, or the file was corrupted/truncated.","commonSituations":"Merging or appending to zip files then reading stale entries, caching entries across stream reopen where the file changed, data-descriptor entries with outdated offsets.","solutions":["Re-create the ZipFile and re-query GetAllEntries before reading if the archive may have changed","Ensure the ZipFileEntry came from the same ZipFile instance over the same stream","Verify the archive's integrity (test extraction or checksum) before reading"],"exampleFix":"// before\nvar entries = oldZip.GetAllEntries(); // stale\nusing var zip = new ZipFile(newStream);\nzip.ReadFile(entries[0]);\n// after\nusing var zip = new ZipFile(newStream);\nvar entry = zip.GetAllEntries().First(e => e.Filename == name);\nzip.ReadFile(entry);","handlingStrategy":"try-catch","validationCode":"// ensure entries are fresh from the same live ZipFile instance\nvar freshEntry = liveZip.GetAllEntries().FirstOrDefault(e => e.Filename == entry.Filename);\nif (freshEntry is null) throw new InvalidOperationException(\"Entry no longer exists in archive\");","typeGuard":null,"tryCatchPattern":"try { zip.ReadFile(entry); }\ncatch (InvalidOperationException) { throw new InvalidDataException($\"Zip entry '{entry.Filename}' has a corrupt header\"); }","preventionTips":["Never cache ZipFileEntry values across archive modifications or stream reopenings","Always read entries obtained from the same ZipFile instance","Test archive integrity after any merge/append operation"],"tags":["zip","corrupt-archive","io"],"backgroundTag":"file-read-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}