Raise proper error when you try to load an empty qcow2 file

Fix #637
This commit is contained in:
Julien Duponchelle committed 2016-08-29 10:18:18 +02:00
1 parent 1885fe62a6
commit 042a69eecf
2 files changed
+10 -1

No files matched your search

+4 -1
View File
@@ -62,7 +62,10 @@ class Qcow2:
with open(self.path, 'rb') as f:
content = f.read(struct.calcsize(struct_format))
self.magic, self.version, self.backing_file_offset, self.backing_file_size = struct.unpack_from(struct_format, content)
try:
self.magic, self.version, self.backing_file_offset, self.backing_file_size = struct.unpack_from(struct_format, content)
except struct.error:
raise Qcow2Error("Invalid file header for {}".format(self.path))
if self.magic != 1363560955: # The first 4 bytes contain the characters 'Q', 'F', 'I' followed by 0xfb.
raise Qcow2Error("Invalid magic for {}".format(self.path))