Skip to content
  • Eric Blake's avatar
    qcow2: Don't allow overflow during cluster allocation · 77d6a215
    Eric Blake authored
    
    
    Our code was already checking that we did not attempt to
    allocate more clusters than what would fit in an INT64 (the
    physical maximimum if we can access a full off_t's worth of
    data).  But this does not catch smaller limits enforced by
    various spots in the qcow2 image description: L1 and normal
    clusters of L2 are documented as having bits 63-56 reserved
    for other purposes, capping our maximum offset at 64PB (bit
    55 is the maximum bit set).  And for compressed images with
    2M clusters, the cap drops the maximum offset to bit 48, or
    a maximum offset of 512TB.  If we overflow that offset, we
    would write compressed data into one place, but try to
    decompress from another, which won't work.
    
    It's actually possible to prove that overflow can cause image
    corruption without this patch; I'll add the iotests separately
    in the next commit.
    
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Reviewed-by: default avatarAlberto Garcia <berto@igalia.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    77d6a215