]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: don't assert() on partition geometry from blkid 42950/head
authorLuca Boccassi <luca.boccassi@gmail.com>
Thu, 9 Jul 2026 14:42:38 +0000 (15:42 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 14 Jul 2026 15:57:14 +0000 (16:57 +0100)
The per-partition loop in dissect_image() reads the start and size (in
512-byte sectors) of each partition from libblkid and guards the
following byte conversions with assert(). Images sizes are input,
rather than programming, so return an error instead of asserting.

Follow-up for 88b3300fdc64d5320fb50d0f369d3fc0885e15e8

src/shared/dissect-image.c

index f9556ea6b493e7b4e0b0b687d9d28e4ad47ce2b0..af19a48eeac06ac8a269a5b72288160ba932faff 100644 (file)
@@ -1309,15 +1309,17 @@ static int dissect_image(
                 start = sym_blkid_partition_get_start(pp);
                 if (start < 0)
                         return errno_or_else(EIO);
-
-                assert((uint64_t) start < UINT64_MAX/512);
+                if ((uint64_t) start >= UINT64_MAX/512)
+                        return log_debug_errno(SYNTHETIC_ERRNO(EOVERFLOW),
+                                               "Partition start LBA too large to convert to a byte offset, refusing.");
 
                 errno = 0;
                 size = sym_blkid_partition_get_size(pp);
                 if (size < 0)
                         return errno_or_else(EIO);
-
-                assert((uint64_t) size < UINT64_MAX/512);
+                if ((uint64_t) size >= UINT64_MAX/512)
+                        return log_debug_errno(SYNTHETIC_ERRNO(EOVERFLOW),
+                                               "Partition size in LBA too large to convert to a byte offset, refusing.");
 
                 /* While probing we need the non-diskseq device node name to access the thing, hence mask off
                  * DISSECT_IMAGE_DISKSEQ_DEVNODE. */