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

[Release] Add symlink verification before opening file #3097

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nncf/common/tensor_statistics/statistics_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import Any, Dict, Optional, Tuple, cast

import nncf
from nncf.common.utils.os import fail_if_symlink
from nncf.common.utils.os import safe_open

METADATA_FILE = "statistics_metadata.json"
Expand Down Expand Up @@ -71,6 +72,7 @@ def load_from_dir(dir_path: str) -> Tuple[Dict[str, Any], Dict[str, str]]:
continue # Skip the metadata file

try:
fail_if_symlink(statistics_file)
Copy link
Collaborator

@kshpv kshpv Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a specific function, such as safe_open, and use it here and below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a missed symlink check instead of the method since this is just a hotfix. A proper solution should be provided as part of the statistics caching implementation change (from pickle).

with gzip.open(statistics_file, "rb") as f:
sanitized_name = statistics_file.name
original_name = mapping.get(sanitized_name, sanitized_name)
Expand Down Expand Up @@ -102,6 +104,7 @@ def dump_to_dir(
mapping[sanitized_name] = original_name

try:
fail_if_symlink(file_path)
with gzip.open(file_path, "wb") as f:
pickle.dump(statistics_value, f)
except (IOError, pickle.PicklingError) as e:
Expand Down
Loading