From: Luca Boccassi Date: Thu, 9 Jul 2026 14:42:38 +0000 (+0100) Subject: dissect-image: don't assert() on partition geometry from blkid X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e6f6ced7295ffef4295ad81ec726c26aa632fd0f;p=thirdparty%2Fsystemd.git dissect-image: don't assert() on partition geometry from blkid 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 --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index f9556ea6b49..af19a48eeac 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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. */