diff options
author | Campbell Barton <campbell@blender.org> | 2022-06-14 07:30:15 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-06-14 07:30:15 +0300 |
commit | 74e960545554b9d6628936fb2eafc76ed34c6cdf (patch) | |
tree | c3bcddd2e47a18c430e5b798cfa1a6a2a24f82ce /release/scripts/modules/blend_render_info.py | |
parent | 6c31bd80e37406e9619a82c57ab3213d9c33e00d (diff) |
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.
Diffstat (limited to 'release/scripts/modules/blend_render_info.py')
-rwxr-xr-x | release/scripts/modules/blend_render_info.py | 14 |
1 files changed, 12 insertions, 2 deletions
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 |