{"record":{"id":"63859ead43858df1","repo":"NationalSecurityAgency/ghidra","slug":"compressed-memory-buffer-is-corrupt","errorCode":null,"errorMessage":"compressed memory buffer is corrupt","messagePattern":"compressed memory buffer is corrupt","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/memory/DBTraceMemoryBufferEntry.java","lineNumber":167,"sourceCode":"\t\tassert isSane(srcOffset, len, blockNum);\n\t\tif (compressed) {\n\t\t\treturn doGetCompressedBytes(buf, srcOffset, len, blockNum);\n\t\t}\n\t\tbuffer.get((blockNum << DBTraceMemorySpace.BLOCK_SHIFT) + srcOffset, buf.array(),\n\t\t\tbuf.arrayOffset() + buf.position(), len);\n\t\tbuf.position(buf.position() + len);\n\t\treturn len;\n\t}\n\n\tprotected int doGetCompressedBytes(ByteBuffer buf, int srcOffset, int len, int blockNum)\n\t\t\tthrows IOException {\n\t\ttry (InputStream is = new GZIPInputStream(new DBBufferInputStream(buffer))) {\n\t\t\tis.skip((blockNum << DBTraceMemorySpace.BLOCK_SHIFT) + srcOffset);\n\t\t\tint amt = is.read(buf.array(), buf.arrayOffset() + buf.position(), len);\n\t\t\tbuf.position(buf.position() + amt);\n\t\t\tif (amt != len) {\n\t\t\t\t// There should always be enough\n\t\t\t\tthrow new IOException(\"compressed memory buffer is corrupt\");\n\t\t\t}\n\t\t\treturn len;\n\t\t}\n\t}\n\n\tprotected void doGetBlock(int blockNum, byte[] data)\n\t\t\tthrows IndexOutOfBoundsException, IOException {\n\t\tassert isInUse(blockNum);\n\t\tif (compressed) {\n\t\t\tdoGetCompressedBlock(blockNum, data);\n\t\t}\n\t\tbuffer.get(blockNum << DBTraceMemorySpace.BLOCK_SHIFT, data);\n\t}\n\n\tprotected void doGetCompressedBlock(int blockNum, byte[] data) throws IOException {\n\t\ttry (InputStream is = new GZIPInputStream(new DBBufferInputStream(buffer))) {\n\t\t\tis.skip(blockNum << DBTraceMemorySpace.BLOCK_SHIFT);\n\t\t\tint amt = is.read(data);","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/memory/DBTraceMemoryBufferEntry.java#L149-L185","documentation":"Thrown by DBTraceMemoryBufferEntry.doGetCompressedBytes() when reading from a GZIP-compressed memory buffer and the decompressed stream returns fewer bytes (amt) than the requested length (len). The method wraps the buffer in a GZIPInputStream and reads len bytes at a computed offset; if amt != len, the compressed buffer is internally inconsistent. An IOException (checked) indicates the compressed data is truncated or corrupt.","triggerScenarios":"Calling doGetCompressedBytes() (via getBytes or doGetBlock) on a DBTraceMemoryBufferEntry flagged as compressed, where the underlying GZIP data stream is shorter than expected. This happens when the compressed buffer was partially written, truncated during save, or corrupted on disk.","commonSituations":"Database corruption after a crash or improper shutdown during a save operation. Disk space exhaustion that truncated a write. Partial trace database copy or transfer. Version or format incompatibility in the compression scheme.","solutions":["Restore the trace database from a backup taken before the corruption.","Re-record the trace from the debugging session if a backup is unavailable.","If only specific memory blocks are affected, clear and re-record those regions.","Investigate storage integrity (disk health, filesystem checks) to prevent recurrence."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    int amt = memory.getBytes(snap, addr, buf);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"compressed memory buffer is corrupt\")) {\n        // corrupted compressed buffer; restore from backup or re-record\n        logger.severe(\"Corrupt compressed buffer at \" + addr + \": \" + e.getMessage());\n    }\n}","preventionTips":["Keep backups of trace databases before upgrades or migrations.","Ensure disk writes complete before shutting down Ghidra.","Avoid concurrent access to trace database files.","Re-record corrupted traces from the original debug session."],"tags":["memory","trace-database","corruption","compression","gzip","checked-exception","io"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}