Unverified Commit 129455f9 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

indicate md5 checksum is not used for security (#5717)

* indicate md5 checksum is not used for security

* add explanation
parent 316c3825
...@@ -7,6 +7,7 @@ import os ...@@ -7,6 +7,7 @@ import os
import os.path import os.path
import pathlib import pathlib
import re import re
import sys
import tarfile import tarfile
import urllib import urllib
import urllib.error import urllib.error
...@@ -62,7 +63,10 @@ def gen_bar_updater() -> Callable[[int, int, int], None]: ...@@ -62,7 +63,10 @@ def gen_bar_updater() -> Callable[[int, int, int], None]:
def calculate_md5(fpath: str, chunk_size: int = 1024 * 1024) -> str: def calculate_md5(fpath: str, chunk_size: int = 1024 * 1024) -> str:
md5 = hashlib.md5() # Setting the `usedforsecurity` flag does not change anything about the functionality, but indicates that we are
# not using the MD5 checksum for cryptography. This enables its usage in restricted environments like FIPS. Without
# it torchvision.datasets is unusable in these environments since we perform a MD5 check everywhere.
md5 = hashlib.md5(**dict(usedforsecurity=False) if sys.version_info >= (3, 9) else dict())
with open(fpath, "rb") as f: with open(fpath, "rb") as f:
for chunk in iter(lambda: f.read(chunk_size), b""): for chunk in iter(lambda: f.read(chunk_size), b""):
md5.update(chunk) md5.update(chunk)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment