Skip to content

Fix load_dependencies crash on externals without a path - #404

Open
1915rising wants to merge 1 commit into
K0lb3:masterfrom
1915rising:fix/326-load-dependencies-none-path
Open

1915rising wants to merge 1 commit into
K0lb3:masterfrom
1915rising:fix/326-load-dependencies-none-path

Conversation

@1915rising

Copy link
Copy Markdown

Fixes #326.

SerializedFile.load_dependencies() crashes for SerializedFiles whose externals include an entry without a path. load_file(None) falls through to check_file_type(None), which raises TypeError: Unsupported type for EndianBinaryReader: <class 'NoneType'> and aborts the whole load. The possible_dependencies loop directly below already tolerates missing files, but the externals loop had no guard at all.

Reproduction (minimal, on current master): a SerializedFile with an external whose path is None raises

File "UnityPy/files/SerializedFile.py", line 410, in load_dependencies
    self.environment.load_file(file_id.path, is_dependency=True)
File "UnityPy/environment.py", line 152, in load_file
    typ, reader = check_file_type(file)
File "UnityPy/helpers/ImportHelper.py", line 52, in check_file_type
    reader = EndianBinaryReader(input_)
TypeError: Unsupported type for EndianBinaryReader: <class 'NoneType'>

An external pointing at a file that does not exist (the reporter's Library/unity default resources case) already returns None from load_file since 8eb6a5e and does not crash; the None-path case is the remaining hole.

Fix: skip externals whose path is falsy, and wrap the externals loop in the same try/except FileNotFoundError the possible_dependencies loop already uses.

Tests:

  • New regression test test_load_dependencies_missing_externals in tests/test_main.py covering a None-path external, a missing-file external, and a missing possible dependency.
  • Suite before: 44 passed, 4 failed. After: 45 passed, 4 failed. The 4 failures are pre-existing and unrelated (test_extractor and 3 test_mesh_helper tests need Git-LFS sample files that are not fetched in my environment) and are identical before and after.

Disclosure: I also have two other PRs open in this repo, #401 and #402, for separate issues.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SerializedFile.load_dependencies() causes crash when dependencies do not exist

1 participant