[PULL v2 02/11] hbitmap: assert that we don't create bitmap larger than INT64_MAX

John Snow jsnow at redhat.com
Wed Mar 18 20:23:32 UTC 2020


From: Vladimir Sementsov-Ogievskiy <vsementsov at virtuozzo.com>

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 <vsementsov at virtuozzo.com>
Reviewed-by: Max Reitz <mreitz at redhat.com>
Reviewed-by: Eric Blake <eblake at redhat.com>
Reviewed-by: John Snow <jsnow at redhat.com>
Message-id: 20200205112041.6003-2-vsementsov at virtuozzo.com
Signed-off-by: John Snow <jsnow at redhat.com>
---
 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




More information about the libvir-list mailing list