Skip to content

Commit 4d10f4a

Browse files
committed
fix Minimum cell size must not be less than 4
1 parent ba4bfcd commit 4d10f4a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

core/storage/btree.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6332,7 +6332,11 @@ fn compute_free_space(page: &PageContent, usable_space: u16) -> u16 {
63326332

63336333
/// Allocate space for a cell on a page.
63346334
fn allocate_cell_space(page_ref: &PageContent, amount: u16, usable_space: u16) -> Result<u16> {
6335-
let amount = amount as usize;
6335+
let mut amount = amount as usize;
6336+
// the minimum cell size is 4 bytes, so we need to ensure that we allocate at least that much space.
6337+
if amount < 4 {
6338+
amount = 4;
6339+
}
63366340

63376341
let (cell_offset, _) = page_ref.cell_pointer_array_offset_and_size();
63386342
let gap = cell_offset + 2 * page_ref.cell_count();

core/storage/sqlite3_ondisk.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,11 @@ impl PageContent {
668668
if overflows {
669669
to_read + n_payload
670670
} else {
671-
len_payload as usize + n_payload
671+
let mut size = len_payload as usize + n_payload;
672+
if size < 4 {
673+
size = 4;
674+
}
675+
size
672676
}
673677
}
674678
PageType::TableLeaf => {
@@ -683,7 +687,11 @@ impl PageContent {
683687
if overflows {
684688
to_read + n_payload + n_rowid
685689
} else {
686-
len_payload as usize + n_payload + n_rowid
690+
let mut size = len_payload as usize + n_payload + n_rowid;
691+
if size < 4 {
692+
size = 4;
693+
}
694+
size
687695
}
688696
}
689697
};

0 commit comments

Comments
 (0)