[Bf-extensions-cvs] [81d0b70] blender-v2.78-release: Make blendfile.py reading/parsing slightly more robust/helpful in broken .blend files cases.
Bastien Montagne
noreply at git.blender.org
Wed Oct 19 14:43:06 CEST 2016
Commit: 81d0b702f651705a6977bbadecb49a74128e3ef6
Author: Bastien Montagne
Date: Mon Sep 26 15:42:03 2016 +0200
Branches: blender-v2.78-release
https://developer.blender.org/rBA81d0b702f651705a6977bbadecb49a74128e3ef6
Make blendfile.py reading/parsing slightly more robust/helpful in broken .blend files cases.
===================================================================
M io_blend_utils/blend/blendfile.py
===================================================================
diff --git a/io_blend_utils/blend/blendfile.py b/io_blend_utils/blend/blendfile.py
index 2e98544..012719f 100644
--- a/io_blend_utils/blend/blendfile.py
+++ b/io_blend_utils/blend/blendfile.py
@@ -123,6 +123,8 @@ class BlendFile:
self.block_header_struct = self.header.create_block_header_struct()
self.blocks = []
self.code_index = {}
+ self.structs = []
+ self.sdna_index_from_id = {}
block = BlendFileBlock(handle, self)
while block.code != b'ENDB':
@@ -140,6 +142,9 @@ class BlendFile:
self.is_modified = False
self.blocks.append(block)
+ if not self.structs:
+ raise Exception("No DNA1 block in file, this is not a valid .blend file!")
+
# cache (could lazy init, incase we never use?)
self.block_from_offset = {block.addr_old: block for block in self.blocks if block.code != b'ENDB'}
@@ -311,12 +316,21 @@ class BlendFileBlock:
self.user_data = None
data = handle.read(bfile.block_header_struct.size)
+
+ if len(data) != bfile.block_header_struct.size:
+ print("WARNING! Blend file seems to be badly truncated!")
+ self.code = b'ENDB'
+ self.size = 0
+ self.addr_old = 0
+ self.sdna_index = 0
+ self.count = 0
+ self.file_offset = 0
+ return
# header size can be 8, 20, or 24 bytes long
# 8: old blend files ENDB block (exception)
# 20: normal headers 32 bit platform
# 24: normal headers 64 bit platform
if len(data) > 15:
-
blockheader = bfile.block_header_struct.unpack(data)
self.code = blockheader[0].partition(b'\0')[0]
if self.code != b'ENDB':
More information about the Bf-extensions-cvs
mailing list