Skip to content

Commit 3c7bf1f

Browse files
committed
Fixed #2
1 parent 1139641 commit 3c7bf1f

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/dbmem-search.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string.h>
1919
#include <stdio.h>
2020
#include <float.h>
21+
#include <limits.h>
2122
#include <time.h>
2223

2324
#ifndef SQLITE_CORE
@@ -87,7 +88,7 @@ int vMemorySearchCursorAllocate (vMemorySearchCursor *c, int entries, bool perfo
8788
// merge: vectorScore, textScore, hash, seq, hasVector, hasFts = 6 arrays * 2*entries (can have both sources)
8889
// final: rank, hash, seq = 3 arrays * entries
8990

90-
int merge_entries = entries * 2;
91+
size_t merge_entries = (size_t)entries * 2;
9192
size_t size = 0;
9293

9394
// fts arrays
@@ -586,7 +587,13 @@ static int vMemorySearchCursorFilter (sqlite3_vtab_cursor *cur, int idxNum, cons
586587

587588
// compute fetch count (oversampling)
588589
int oversample = dbmem_context_search_oversample(ctx);
589-
int fetch_count = (oversample > 0) ? max_results * oversample : max_results;
590+
int fetch_count;
591+
if (oversample > 0) {
592+
if (max_results > INT_MAX / oversample) return SQLITE_TOOBIG;
593+
fetch_count = max_results * oversample;
594+
} else {
595+
fetch_count = max_results;
596+
}
590597

591598
// allocate internal cursor buffer
592599
int rc = vMemorySearchCursorAllocate(c, fetch_count, perform_fts);

0 commit comments

Comments
 (0)