Skip to content

Commit 323e9f5

Browse files
committed
Fix unintentional exception inspecting VMDK
It looks like a raise statement was left in the virtual_size property handler for VMDK, which should have been converted to a log at some point. All the other inspectors return zero for virtual_size if the format does not match or they are unable to parse the data. This converts that raise to a log, and adds a test to make sure we make it far enough in the processing of the complex VMDK format to ensure that behavior. Closes-Bug: #1983279 Change-Id: I0352ab6b2c00055de094ac5902b8d50941d06dcf (cherry picked from commit 199722a) (cherry picked from commit 07f9874)
1 parent 5fbf473 commit 323e9f5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

glance/common/format_inspector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def virtual_size(self):
567567
else:
568568
vmdktype = b'formatnotfound'
569569
if vmdktype != b'monolithicSparse':
570-
raise ImageFormatError('Unsupported VMDK format %s' % vmdktype)
570+
LOG.warning('Unsupported VMDK format %s', vmdktype)
571571
return 0
572572

573573
# If we have the descriptor, we definitely have the header

glance/tests/unit/common/test_format_inspector.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,24 @@ def test_vmdk_invalid(self):
153153
def test_vdi_invalid(self):
154154
self._test_format_with_invalid_data('vdi')
155155

156+
def test_vmdk_invalid_type(self):
157+
fmt = format_inspector.get_inspector('vmdk')()
158+
wrapper = format_inspector.InfoWrapper(open(__file__, 'rb'), fmt)
159+
while True:
160+
chunk = wrapper.read(32)
161+
if not chunk:
162+
break
163+
164+
wrapper.close()
165+
166+
fake_rgn = mock.MagicMock()
167+
fake_rgn.complete = True
168+
fake_rgn.data = b'foocreateType="someunknownformat"bar'
169+
170+
with mock.patch.object(fmt, 'has_region', return_value=True):
171+
with mock.patch.object(fmt, 'region', return_value=fake_rgn):
172+
self.assertEqual(0, fmt.virtual_size)
173+
156174

157175
class TestFormatInspectorInfra(test_utils.BaseTestCase):
158176
def _test_capture_region_bs(self, bs):

0 commit comments

Comments
 (0)