Skip to content

Commit

Permalink
[Release] Add symlink verification before opening file (#3097)
Browse files Browse the repository at this point in the history
### Changes

- As stated in the title.

### Reason for changes

- Fix after #3017.

### Related tickets

- 157068

### Tests

- test_examples/620/ - passed
  • Loading branch information
KodiaqQ authored Nov 19, 2024
1 parent 8b83107 commit 7510b4f
Showing 1 changed file with 3 additions and 0 deletions.
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)
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

0 comments on commit 7510b4f

Please sign in to comment.