Commit e39e959e authored by Kevin Wolf's avatar Kevin Wolf
Browse files

luks: Turn invalid assertion into check



The .bdrv_getlength implementation of the crypto block driver asserted
that the payload offset isn't after EOF. This is an invalid assertion to
make as the image file could be corrupted. Instead, check it and return
-EIO if the file is too small for the payload offset.

Zero length images are fine, so trigger -EIO only on offset > len, not
on offset >= len as the assertion did before.

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
parent 1bedcaf1
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -518,7 +518,10 @@ static int64_t block_crypto_getlength(BlockDriverState *bs)

    uint64_t offset = qcrypto_block_get_payload_offset(crypto->block);
    assert(offset < INT64_MAX);
    assert(offset < len);

    if (offset > len) {
        return -EIO;
    }

    len -= offset;