Skip to content

Commit cc47b71

Browse files
kk7dsmarkgoddard
authored andcommitted
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) (cherry picked from commit ba98022b98ef5b9c98e1d7d20c88e1ca4b23fa80) (cherry picked from commit a8dadcd7994c88a61f94341286b4bcd693b51b32)
1 parent 8e00bf8 commit cc47b71

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

glance/common/format_inspector.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,23 @@ def safety_check(self):
366366
not self.has_unknown_features)
367367

368368

369+
class QEDInspector(FileInspector):
370+
def __init__(self, tracing=False):
371+
super().__init__(tracing)
372+
self.new_region('header', CaptureRegion(0, 512))
373+
374+
@property
375+
def format_match(self):
376+
if not self.region('header').complete:
377+
return False
378+
return self.region('header').data.startswith(b'QED\x00')
379+
380+
def safety_check(self):
381+
# QED format is not supported by anyone, but we want to detect it
382+
# and mark it as just always unsafe.
383+
return False
384+
385+
369386
# The VHD (or VPC as QEMU calls it) format consists of a big-endian
370387
# 512-byte "footer" at the beginning of the file with various
371388
# information, most of which does not matter to us:
@@ -868,6 +885,7 @@ def get_inspector(format_name):
868885
'vhdx': VHDXInspector,
869886
'vmdk': VMDKInspector,
870887
'vdi': VDIInspector,
888+
'qed': QEDInspector,
871889
}
872890

873891
return formats.get(format_name)

glance/tests/unit/common/test_format_inspector.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ def test_from_file_reads_minimum(self):
145145
# a local file.
146146
self.assertLess(fmt.actual_size, file_size)
147147

148+
def test_qed_always_unsafe(self):
149+
img = self._create_img('qed', 10 * units.Mi)
150+
fmt = format_inspector.get_inspector('qed').from_file(img)
151+
self.assertTrue(fmt.format_match)
152+
self.assertFalse(fmt.safety_check())
153+
148154
def test_qcow2_safety_checks(self):
149155
# Create backing and data-file names (and initialize the backing file)
150156
backing_fn = tempfile.mktemp(prefix='backing')

0 commit comments

Comments
 (0)