Skip to content

Commit 60beb13

Browse files
committed
reftable/block: check deflateInit() return value
block_writer_init() allocates a z_stream and calls deflateInit() to prepare it for compressing log records. The return value of deflateInit() is silently discarded. If zlib initialization fails (e.g., Z_MEM_ERROR when the system is under memory pressure), the z_stream is left in an undefined state. Subsequent deflate() calls in block_writer_finish() then operate on this uninitialized stream. Depending on the zlib implementation, this can produce silently corrupted compressed data (which would be written to the reftable file and discovered only when a later reader fails to inflate) or crash outright. The function already uses REFTABLE_ZLIB_ERROR for deflate() failures later in the code path (lines 171, 199), so returning the same error code for deflateInit() failure is consistent. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent c530728 commit 60beb13

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

reftable/block.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ int block_writer_init(struct block_writer *bw, uint8_t typ, uint8_t *block,
8787
REFTABLE_CALLOC_ARRAY(bw->zstream, 1);
8888
if (!bw->zstream)
8989
return REFTABLE_OUT_OF_MEMORY_ERROR;
90-
deflateInit(bw->zstream, 9);
90+
if (deflateInit(bw->zstream, 9) != Z_OK)
91+
return REFTABLE_ZLIB_ERROR;
9192
}
9293

9394
return 0;

0 commit comments

Comments
 (0)