]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: avoid length overflow in extents returned by Stupid 29024/head
authorIgor Fedotov <ifedotov@suse.com>
Tue, 9 Jul 2019 18:02:08 +0000 (21:02 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Fri, 12 Jul 2019 15:34:26 +0000 (18:34 +0300)
Allocator.

Fixes: http://tracker.ceph.com/issues/40703
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit e1b4984a63e79ab2e2aec7aa17bd80a77e79ec8c)

 Conflicts:
src/test/objectstore/Allocator_test.cc
 inconsistency with the old gtest version

src/os/bluestore/StupidAllocator.cc
src/test/objectstore/Allocator_test.cc

index 35d6d91e1cdff07294cb125968314254a04fb2cc..8f049c3533e9849d17f78186aadd543f3950ee56 100644 (file)
@@ -206,10 +206,13 @@ int64_t StupidAllocator::allocate(
     bool can_append = true;
     if (!extents->empty()) {
       bluestore_pextent_t &last_extent  = extents->back();
-      if ((last_extent.end() == offset) &&
-         ((last_extent.length + length) <= max_alloc_size)) {
-       can_append = false;
-       last_extent.length += length;
+      if (last_extent.end() == offset) {
+        uint64_t l64 = last_extent.length;
+        l64 += length;
+        if (l64 < 0x100000000 && l64 <= max_alloc_size) {
+         can_append = false;
+         last_extent.length += length;
+        }
       }
     }
     if (can_append) {
index 959932af9e5980f3dc36bd1bf032da5f90401e78..ded6951f49cc62b9c72b08979446f87371a3a30f 100644 (file)
@@ -316,6 +316,27 @@ TEST_P(AllocTest, test_alloc_bug_24598)
   EXPECT_EQ(tmp.size(), 1);
 }
 
+//Verifies issue from
+//http://tracker.ceph.com/issues/40703
+//
+TEST_P(AllocTest, test_alloc_big2)
+{
+  int64_t block_size = 4096;
+  int64_t blocks = 1048576 * 2;
+  int64_t mas = 1024*1024;
+  init_alloc(blocks*block_size, block_size);
+  alloc->init_add_free(0, blocks * block_size);
+  
+  PExtentVector extents;
+  uint64_t need = block_size * blocks / 4; // 2GB
+  EXPECT_EQ(need,
+      alloc->allocate(need, mas, 0, &extents));
+  need = block_size * blocks / 4; // 2GB
+  EXPECT_EQ(need,
+      alloc->allocate(need, mas, 0, &extents));
+  EXPECT_TRUE(extents[0].length > 0);
+}
+
 INSTANTIATE_TEST_CASE_P(
   Allocator,
   AllocTest,