Skip to content

Commit 391b900

Browse files
TreeHunter9Artyom Ivanov
andauthored
fix(pio): Replace 32-bit offset calculation with 64-bit in PIO_extend (#8697)
* fix(pio): Correct 32-bit offset calculation in PIO_extend Replaces 32-bit arguments with 64-bit equivalents to prevent overflow when handling large files (>4GB). The original implementation incorrectly calculated offsets as 32-bit values, which made it impossible to extend the file. * refactor(pio): Add distinct variables for offset and length --------- Co-authored-by: Artyom Ivanov <artyom.ivanov@red-soft.ru>
1 parent 58d28af commit 391b900

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/jrd/os/posix/unix.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,13 @@ void PIO_extend(thread_db* tdbb, jrd_file* file, const ULONG extPages, const USH
323323
const ULONG filePages = PIO_get_number_of_pages(file, pageSize);
324324
const ULONG extendBy = MIN(MAX_ULONG - filePages, extPages);
325325

326+
const off_t offset = static_cast<off_t>(filePages) * pageSize;
327+
const off_t length = static_cast<off_t>(extendBy) * pageSize;
328+
326329
int r;
327330
for (r = 0; r < IO_RETRY; r++)
328331
{
329-
int err = fallocate(file->fil_desc, 0, filePages * pageSize, extendBy * pageSize);
332+
int err = fallocate(file->fil_desc, 0, offset, length);
330333
if (err == 0)
331334
break;
332335

0 commit comments

Comments
 (0)