Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix unsafe dictionary access #3751

Open
wants to merge 1 commit into
base: dev-1.x
Choose a base branch
from

Conversation

Joris-Kuehl-TU-Berlin
Copy link

Motivation

The method init_model in mmseg/apis/inference.py has an unsafe dictionary access in line 61. The key 'meta' is accessed directly, even though the following lines always use checkpoint.get('meta') to ensure it even exists and have functional handling for the case that it doesn't (in the else case). As a result, the program will throw a KeyError before ever reaching the already implemented handling of this very case. This bug is the reason for #3558.

Modification

Simply moving the dictionary access AFTER the check that the key exists will suffice. This will allow init_model to reach the else case when checkpoint['meta'] does not exist.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Aug 5, 2024

CLA assistant check
All committers have signed the CLA.

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.

2 participants