]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: fixup_range() clamps offsets to valid part range
authorCasey Bodley <cbodley@redhat.com>
Wed, 27 Mar 2019 17:52:59 +0000 (13:52 -0400)
committerCasey Bodley <cbodley@redhat.com>
Wed, 27 Mar 2019 18:02:23 +0000 (14:02 -0400)
Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_crypt.cc
src/test/rgw/test_rgw_crypto.cc

index a0a225cbf486c5dc47ee2c34eb348d6a2dc94e5c..00125a07539e678a56c93db3c5cac01cbea9ff93 100644 (file)
@@ -575,23 +575,22 @@ int RGWGetObj_BlockDecrypt::fixup_range(off_t& bl_ofs, off_t& bl_end) {
     }
     //in_ofs is inside block i
     size_t j = 0;
-    while (j<parts_len.size() && (in_end >= (off_t)parts_len[j])) {
+    while (j<(parts_len.size() - 1) && (in_end >= (off_t)parts_len[j])) {
       in_end -= parts_len[j];
       j++;
     }
-    //in_end is inside block j
+    //in_end is inside part j, OR j is the last part
 
-    size_t rounded_end;
-    rounded_end = ( in_end & ~(block_size - 1) ) + (block_size - 1);
-    if (rounded_end + 1 >= parts_len[j]) {
+    size_t rounded_end = ( in_end & ~(block_size - 1) ) + (block_size - 1);
+    if (rounded_end > parts_len[j]) {
       rounded_end = parts_len[j] - 1;
     }
 
     enc_begin_skip = in_ofs & (block_size - 1);
     ofs = bl_ofs - enc_begin_skip;
     end = bl_end;
-    bl_ofs = bl_ofs - enc_begin_skip;
     bl_end += rounded_end - in_end;
+    bl_ofs = std::min(bl_ofs - enc_begin_skip, bl_end);
   }
   else
   {
index 5f6e805f83f5cbd03f00c66cd545ae7584ed038b..1ab9559284034bff99428257d76ad1610ff4bca1 100644 (file)
@@ -680,11 +680,11 @@ TEST(TestRGWCrypto, check_RGWGetObj_BlockDecrypt_fixup_invalid_ranges)
   // would've returned a 411 before reaching, but we're just doing this to make
   // sure we don't have invalid access
   ASSERT_EQ(fixup_range(&decrypt, obj_size - 1, obj_size + 100),
-           range_t(obj_size - 4096, obj_size + 4095));
+            range_t(obj_size - 4096, obj_size - 1));
   ASSERT_EQ(fixup_range(&decrypt, obj_size, obj_size + 1),
-           range_t(obj_size, obj_size + 4095));
+            range_t(obj_size - 1, obj_size - 1));
   ASSERT_EQ(fixup_range(&decrypt, obj_size+1, obj_size + 100),
-           range_t(obj_size, obj_size + 4095));
+            range_t(obj_size - 1, obj_size - 1));
 
 }