Merge "Add QED format detection to format_inspector" into stable/2024.1

This commit is contained in:
Zuul 2024-07-04 21:19:10 +00:00 committed by Gerrit Code Review
commit 4ac3c1b0f8
2 changed files with 24 additions and 0 deletions

View File

@ -366,6 +366,23 @@ class QcowInspector(FileInspector):
not self.has_unknown_features)
class QEDInspector(FileInspector):
def __init__(self, tracing=False):
super().__init__(tracing)
self.new_region('header', CaptureRegion(0, 512))
@property
def format_match(self):
if not self.region('header').complete:
return False
return self.region('header').data.startswith(b'QED\x00')
def safety_check(self):
# QED format is not supported by anyone, but we want to detect it
# and mark it as just always unsafe.
return False
# The VHD (or VPC as QEMU calls it) format consists of a big-endian
# 512-byte "footer" at the beginning of the file with various
# information, most of which does not matter to us:
@ -879,6 +896,7 @@ def get_inspector(format_name):
'vhdx': VHDXInspector,
'vmdk': VMDKInspector,
'vdi': VDIInspector,
'qed': QEDInspector,
}
return formats.get(format_name)

View File

@ -179,6 +179,12 @@ class TestFormatInspectors(test_utils.BaseTestCase):
# a local file.
self.assertLess(fmt.actual_size, file_size)
def test_qed_always_unsafe(self):
img = self._create_img('qed', 10 * units.Mi)
fmt = format_inspector.get_inspector('qed').from_file(img)
self.assertTrue(fmt.format_match)
self.assertFalse(fmt.safety_check())
def _test_vmdk_bad_descriptor_offset(self, subformat=None):
format_name = 'vmdk'
image_size = 10 * units.Mi