From 90a613dd37bb26776ad7a7725024490d90f38400 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Thu, 21 Nov 2024 13:38:10 +0100 Subject: [PATCH] Add check that TID range is not exhausted We ensure that we do not lose part of the block number when shifting it to fit in the upper part of the block number of the encoded TID. --- tsl/src/hypercore/arrow_tts.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tsl/src/hypercore/arrow_tts.h b/tsl/src/hypercore/arrow_tts.h index 5436e4d18cd..48c9f9c8303 100644 --- a/tsl/src/hypercore/arrow_tts.h +++ b/tsl/src/hypercore/arrow_tts.h @@ -136,8 +136,12 @@ hypercore_tid_encode(ItemPointerData *out_tid, const ItemPointerData *in_tid, ui Assert(offset < OFFSET_LIMIT); Assert(tuple_index != InvalidTupleIndex); - /* Ensure that we are not using the compressed flag in the encoded tid */ - Ensure((COMPRESSED_FLAG | encoded_tid) != encoded_tid, "block number too large"); + /* Ensure that we are not using the compressed flag in the encoded tid and + * that the most significant bits of the block number was not truncated + * from the shifting. If that happens, we have a block number that is too + * large for the encoding. */ + Ensure((COMPRESSED_FLAG | encoded_tid) != encoded_tid && (encoded_tid >> OFFSET_BITS) == block, + "block number too large"); ItemPointerSet(out_tid, COMPRESSED_FLAG | encoded_tid, tuple_index); }