Add QED format detection to format_inspector

This merely recognizes this format and always marks it as unsafe
because no service supports it. This prevents someone from uploading
one that we will ask qemu-img to inspect.

Change-Id: Ieea7b7eb0f380571bd4937cded920776e05f7ec4
(cherry picked from commit 4096c5aff1d046d5c28d0e4a69b3c9574e9e8cc8)
This commit is contained in:
Dan Smith 2024-06-27 09:33:55 -07:00 committed by Abhishek Kekane
parent f482a92f5a
commit 83acfc4620
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