fix Minimum cell size must not be less than 4

This commit is contained in:
meteorgan
2025-07-06 17:15:15 +08:00
parent 3065416bb2
commit 04575456a9
2 changed files with 15 additions and 3 deletions

View File

@@ -6364,7 +6364,11 @@ fn compute_free_space(page: &PageContent, usable_space: u16) -> u16 {
/// Allocate space for a cell on a page.
fn allocate_cell_space(page_ref: &PageContent, amount: u16, usable_space: u16) -> Result<u16> {
let amount = amount as usize;
let mut amount = amount as usize;
// the minimum cell size is 4 bytes, so we need to ensure that we allocate at least that much space.
if amount < 4 {
amount = 4;
}
let (cell_offset, _) = page_ref.cell_pointer_array_offset_and_size();
let gap = cell_offset + 2 * page_ref.cell_count();

View File

@@ -668,7 +668,11 @@ impl PageContent {
if overflows {
to_read + n_payload
} else {
len_payload as usize + n_payload
let mut size = len_payload as usize + n_payload;
if size < 4 {
size = 4;
}
size
}
}
PageType::TableLeaf => {
@@ -683,7 +687,11 @@ impl PageContent {
if overflows {
to_read + n_payload + n_rowid
} else {
len_payload as usize + n_payload + n_rowid
let mut size = len_payload as usize + n_payload + n_rowid;
if size < 4 {
size = 4;
}
size
}
}
};