[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 02/11] hbitmap: assert that we don't create bitmap larger than
From: |
John Snow |
Subject: |
[PULL v2 02/11] hbitmap: assert that we don't create bitmap larger than INT64_MAX |
Date: |
Wed, 18 Mar 2020 16:23:32 -0400 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
We have APIs which returns signed int64_t, to be able to return error.
Therefore we can't handle bitmaps with absolute size larger than
(INT64_MAX+1). Still, keep maximum to be INT64_MAX which is a bit
safer.
Note, that bitmaps are used to represent disk images, which can't
exceed INT64_MAX anyway.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: John Snow <address@hidden>
Message-id: address@hidden
Signed-off-by: John Snow <address@hidden>
---
util/hbitmap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 242c6e519c..7f9b3e0cd7 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -716,6 +716,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
HBitmap *hb = g_new0(struct HBitmap, 1);
unsigned i;
+ assert(size <= INT64_MAX);
hb->orig_size = size;
assert(granularity >= 0 && granularity < 64);
@@ -746,6 +747,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size)
uint64_t num_elements = size;
uint64_t old;
+ assert(size <= INT64_MAX);
hb->orig_size = size;
/* Size comes in as logical elements, adjust for granularity. */
--
2.21.1
- [PULL v2 00/11] Bitmaps patches, John Snow, 2020/03/18
- [PULL v2 01/11] build: Silence clang warning on older glib autoptr usage, John Snow, 2020/03/18
- [PULL v2 02/11] hbitmap: assert that we don't create bitmap larger than INT64_MAX,
John Snow <=
- [PULL v2 03/11] hbitmap: move hbitmap_iter_next_word to hbitmap.c, John Snow, 2020/03/18
- [PULL v2 04/11] hbitmap: unpublish hbitmap_iter_skip_words, John Snow, 2020/03/18
- [PULL v2 11/11] block/qcow2-bitmap: use bdrv_dirty_bitmap_next_dirty, John Snow, 2020/03/18
- [PULL v2 06/11] block/dirty-bitmap: switch _next_dirty_area and _next_zero to int64_t, John Snow, 2020/03/18
- [PULL v2 10/11] nbd/server: use bdrv_dirty_bitmap_next_dirty_area, John Snow, 2020/03/18
- [PULL v2 09/11] nbd/server: introduce NBDExtentArray, John Snow, 2020/03/18
- [PULL v2 07/11] block/dirty-bitmap: add _next_dirty API, John Snow, 2020/03/18
- [PULL v2 08/11] block/dirty-bitmap: improve _next_dirty_area API, John Snow, 2020/03/18
- [PULL v2 05/11] hbitmap: drop meta bitmaps as they are unused, John Snow, 2020/03/18
- Re: [PULL v2 00/11] Bitmaps patches, Peter Maydell, 2020/03/19