[Bf-blender-cvs] [74e96054555] master: blend_render_info: minor improvements to file parsing
Campbell Barton
noreply at git.blender.org
Tue Jun 14 06:54:14 CEST 2022
Commit: 74e960545554b9d6628936fb2eafc76ed34c6cdf
Author: Campbell Barton
Date: Tue Jun 14 14:30:15 2022 +1000
Branches: master
https://developer.blender.org/rB74e960545554b9d6628936fb2eafc76ed34c6cdf
blend_render_info: minor improvements to file parsing
- Stop once `ENDB` is reached, as files could include additional data.
- Prevent the possibility of an infinite loop from malformed BHEAD
blocks that could seek backwards in the file.
===================================================================
M release/scripts/modules/blend_render_info.py
===================================================================
diff --git a/release/scripts/modules/blend_render_info.py b/release/scripts/modules/blend_render_info.py
index 4ba818a19e5..37c5f6dd3ba 100755
--- a/release/scripts/modules/blend_render_info.py
+++ b/release/scripts/modules/blend_render_info.py
@@ -85,7 +85,13 @@ def _read_blend_rend_chunk_from_file(blendfile, filepath):
sizeof_bhead = 24 if is_64_bit else 20
- while len(bhead_id := blendfile.read(4)) == 4:
+ # Should always be 4, but a malformed/corrupt file may be less.
+ while (bhead_id := blendfile.read(4)) != b'ENDB':
+
+ if len(bhead_id) != 4:
+ sys.stderr.write("Unable to read until ENDB block (corrupt file): %s\n" % filepath)
+ break
+
sizeof_data_left = struct.unpack('>i' if is_big_endian else '<i', blendfile.read(4))[0]
# 4 from the `head_id`, another 4 for the size of the BHEAD.
sizeof_bhead_left = sizeof_bhead - 8
@@ -107,8 +113,12 @@ def _read_blend_rend_chunk_from_file(blendfile, filepath):
scenes.append((start_frame, end_frame, scene_name))
- if sizeof_data_left != 0:
+ if sizeof_data_left > 0:
blendfile.seek(sizeof_data_left, SEEK_CUR)
+ elif sizeof_data_left < 0:
+ # Very unlikely, but prevent attempting to further parse corrupt data.
+ sys.stderr.write("Error calculating next block (corrupt file): %s\n" % filepath)
+ break
return scenes
More information about the Bf-blender-cvs
mailing list