diff --git a/src/hnswutils.c b/src/hnswutils.c index d3ba911..093e7ef 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -300,6 +300,9 @@ HnswGetMetaPageInfo(Relation index, int *m, HnswElement * entryPoint) page = BufferGetPage(buf); metap = HnswPageGetMeta(page); + if (unlikely(metap->magicNumber != HNSW_MAGIC_NUMBER)) + elog(ERROR, "hnsw index is not valid"); + if (m != NULL) *m = metap->m; diff --git a/src/ivfinsert.c b/src/ivfinsert.c index fd1ea17..1da4822 100644 --- a/src/ivfinsert.c +++ b/src/ivfinsert.c @@ -19,6 +19,9 @@ FindInsertPage(Relation index, Datum *values, BlockNumber *insertPage, ListInfo FmgrInfo *procinfo; Oid collation; + /* Ensure index is valid */ + IvfflatGetMetaPageInfo(index, NULL, NULL); + /* Avoid compiler warning */ listInfo->blkno = nextblkno; listInfo->offno = FirstOffsetNumber; diff --git a/src/ivfutils.c b/src/ivfutils.c index 74a4159..2098a64 100644 --- a/src/ivfutils.c +++ b/src/ivfutils.c @@ -170,7 +170,11 @@ IvfflatGetMetaPageInfo(Relation index, int *lists, int *dimensions) page = BufferGetPage(buf); metap = IvfflatPageGetMeta(page); - *lists = metap->lists; + if (unlikely(metap->magicNumber != IVFFLAT_MAGIC_NUMBER)) + elog(ERROR, "ivfflat index is not valid"); + + if (lists != NULL) + *lists = metap->lists; if (dimensions != NULL) *dimensions = metap->dimensions;