{"record":{"id":"2f881477f668da04","repo":"prestodb/presto","slug":"deserialized-mapblock-violates-invariants-key-d","errorCode":null,"errorMessage":"Deserialized MapBlock violates invariants: key %d, value %d","messagePattern":"Deserialized MapBlock violates invariants: key (.+?), value (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/MapBlockEncoding.java","lineNumber":87,"sourceCode":"        }\n        EncoderUtil.encodeNullsAsBits(sliceOutput, block);\n    }\n\n    @Override\n    public Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput)\n    {\n        Block keyBlock = blockEncodingSerde.readBlock(sliceInput);\n        Block valueBlock = blockEncodingSerde.readBlock(sliceInput);\n\n        int hashTableLength = sliceInput.readInt();\n        int[] hashTable = null;\n        if (hashTableLength >= 0) {\n            hashTable = new int[hashTableLength];\n            sliceInput.readBytes(wrappedIntArray(hashTable));\n        }\n\n        if (keyBlock.getPositionCount() != valueBlock.getPositionCount()) {\n            throw new IllegalArgumentException(\n                    format(\"Deserialized MapBlock violates invariants: key %d, value %d\", keyBlock.getPositionCount(), valueBlock.getPositionCount()));\n        }\n\n        if (hashTable != null && keyBlock.getPositionCount() * HASH_MULTIPLIER != hashTable.length) {\n            throw new IllegalArgumentException(\n                    format(\"Deserialized MapBlock violates invariants: expected hashtable size %d, actual hashtable size %d\", keyBlock.getPositionCount() * HASH_MULTIPLIER, hashTable.length));\n        }\n\n        int positionCount = sliceInput.readInt();\n        int[] offsets = new int[positionCount + 1];\n        sliceInput.readBytes(wrappedIntArray(offsets));\n        Optional<boolean[]> mapIsNull = EncoderUtil.decodeNullBits(sliceInput, positionCount);\n        return MapType.createMapBlockInternal(0, positionCount, mapIsNull, offsets, keyBlock, valueBlock, new HashTables(Optional.ofNullable(hashTable), positionCount));\n    }\n}\n","sourceCodeStart":69,"sourceCodeEnd":103,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/MapBlockEncoding.java#L69-L103","documentation":"readBlock deserializes a MapBlock from a SliceInput and verifies structural invariants; the key and value blocks must have equal position counts because each key maps 1:1 to a value. A mismatch means the serialized payload is corrupt, truncated, or was produced by an incompatible writer, so readBlock throws IllegalArgumentException.","triggerScenarios":"Reading a MapBlock from serialized bytes where the encoded keyBlock has a different positionCount than the encoded valueBlock — corrupted network/storage payload, wrong offsets, or version mismatch between serializer and deserializer.","commonSituations":"Exchange or spill data corrupted in transit; a Presto version skew where block encoding changed; bugs in custom block writers.","solutions":["Verify integrity of the serialized data source (checksums, exchange retry)","Ensure all nodes run compatible Presto versions (same block encoding format)","Re-fetch the block from the origin instead of using the corrupt payload"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Block block = blockEncoding.readBlock(sliceInput);\n} catch (IllegalArgumentException e) {\n    // log corrupt payload, re-fetch from origin, alert on checksum mismatch\n}","preventionTips":["Enable checksums on exchange/spill channels","Keep cluster-wide Presto versions consistent","Never hand-edit serialized block bytes"],"tags":["deserialization","map-block","data-corruption"],"backgroundTag":"deserialization-invariant-violated","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}