Skip to content

Commit 16228aa

Browse files
Mikael RonströmPiotr Obrzut
authored andcommitted
BUG#25508233: Fix error in calculation that gets out of hand with file sizes above 4GByte
(cherry picked from commit 53726f1f8d34889b43f65d25fd346f8f3adeff94)
1 parent 675d9cf commit 16228aa

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

storage/ndb/src/kernel/blocks/tsman.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ Tsman::execCREATE_FILE_IMPL_REQ(Signal* signal)
718718
client_unlock(number(), __LINE__);
719719
}
720720

721-
static inline Uint64 DIV(Uint64 a, Uint64 b){ return (a + b - 1) / b;}
721+
static inline Uint64 DIV(Uint64 a, Uint64 b){ return (a + b - Uint64(1)) / b;}
722722

723723
void
724724
Tsman::release_extent_pages(Signal* signal, Ptr<Datafile> ptr)
@@ -858,7 +858,7 @@ Tsman::calculate_extent_pages_in_file(Uint64 extents,
858858
ndbrequire(eh_words < File_formats::Datafile::extent_page_words(v2));
859859
Uint64 extents_per_page = (Uint64)
860860
File_formats::Datafile::extent_page_words(v2) / eh_words;
861-
return (extents + extents_per_page - 1) / extents_per_page;
861+
return (extents + extents_per_page - Uint64(1)) / extents_per_page;
862862
}
863863

864864
int
@@ -942,11 +942,11 @@ Tsman::open_file(Signal* signal,
942942
req->file_size_hi = hi;
943943
req->file_size_lo = lo;
944944

945-
Uint64 pages = (Uint64(hi) << 32 | lo) / File_formats::NDB_PAGE_SIZE;
945+
Uint64 pages = (Uint64(hi) << 32 | Uint64(lo)) / Uint64(File_formats::NDB_PAGE_SIZE);
946946
Uint32 extent_size = ts_ptr.p->m_extent_size; // Extent size in #pages
947-
Uint64 extents = (pages + extent_size - 1) / extent_size;
948-
extents = extents ? extents : 1;
949-
Uint64 data_pages = extents * extent_size;
947+
Uint64 extents = (pages + Uint64(extent_size) - Uint64(1)) / Uint64(extent_size);
948+
extents = extents ? extents : Uint64(1);
949+
Uint64 data_pages = extents * Uint64(extent_size);
950950

951951
/**
952952
* We always calculate the file size by using the v1 format to ensure
@@ -956,7 +956,7 @@ Tsman::open_file(Signal* signal,
956956
extent_size,
957957
data_pages,
958958
v2);
959-
Uint64 tot_pages = 1 + extent_pages + data_pages;
959+
Uint64 tot_pages = Uint64(1) + extent_pages + data_pages;
960960

961961
// TODO check overflow in cast
962962
ptr.p->m_create.m_extent_pages = Uint32(extent_pages);
@@ -965,7 +965,7 @@ Tsman::open_file(Signal* signal,
965965
/**
966966
* Update file size
967967
*/
968-
Uint64 bytes = tot_pages * File_formats::NDB_PAGE_SIZE;
968+
Uint64 bytes = tot_pages * Uint64(File_formats::NDB_PAGE_SIZE);
969969
hi = (Uint32)(bytes >> 32);
970970
lo = (Uint32)(bytes & 0xFFFFFFFF);
971971
req->file_size_hi = hi;
@@ -1202,8 +1202,10 @@ Tsman::execFSOPENCONF(Signal* signal)
12021202
Uint64 file_size_lo = conf->file_size_lo;
12031203
Uint64 file_size = (file_size_hi << 32) + file_size_lo;
12041204
Uint64 calc_file_size =
1205-
(1 + ptr.p->m_create.m_data_pages + ptr.p->m_create.m_extent_pages) *
1206-
File_formats::NDB_PAGE_SIZE;
1205+
(Uint64(1) +
1206+
Uint64(ptr.p->m_create.m_data_pages) +
1207+
Uint64(ptr.p->m_create.m_extent_pages)) *
1208+
Uint64(File_formats::NDB_PAGE_SIZE);
12071209
if (file_size != calc_file_size)
12081210
{
12091211
/**
@@ -1218,7 +1220,7 @@ Tsman::execFSOPENCONF(Signal* signal)
12181220
data_pages,
12191221
false);
12201222
Uint64 calc_file_size_v1 =
1221-
(1 + data_pages + extent_pages) * File_formats::NDB_PAGE_SIZE;
1223+
(Uint64(1) + data_pages + extent_pages) * Uint64(File_formats::NDB_PAGE_SIZE);
12221224
if (file_size == calc_file_size_v1)
12231225
{
12241226
jam();

0 commit comments

Comments
 (0)