Skip to content

Commit cdfb6e4

Browse files
committed
fix: replace weak hash functions with SHA-256
1 parent 8382f08 commit cdfb6e4

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

pylib/gyp/MSVSNew.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def MakeGuid(name, seed="msvs_new"):
3434
3535
Args:
3636
name: Target name.
37-
seed: Seed for MD5 hash.
37+
seed: Seed for SHA-256 hash.
3838
Returns:
3939
A GUID-line string calculated from the name and seed.
4040
@@ -44,8 +44,8 @@ def MakeGuid(name, seed="msvs_new"):
4444
determine the GUID to refer to explicitly. It also means that the GUID will
4545
not change when the project for a target is rebuilt.
4646
"""
47-
# Calculate a MD5 signature for the seed and name.
48-
d = hashlib.md5((str(seed) + str(name)).encode("utf-8")).hexdigest().upper()
47+
# Calculate a SHA-256 signature for the seed and name.
48+
d = hashlib.sha256((str(seed) + str(name)).encode("utf-8")).hexdigest().upper()
4949
# Convert most of the signature to GUID form (discard the rest)
5050
guid = (
5151
"{"

pylib/gyp/generator/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ def WriteMakeRule(
21692169
# - The multi-output rule will have an do-nothing recipe.
21702170

21712171
# Hash the target name to avoid generating overlong filenames.
2172-
cmddigest = hashlib.sha1(
2172+
cmddigest = hashlib.sha256(
21732173
(command or self.target).encode("utf-8")
21742174
).hexdigest()
21752175
intermediate = "%s.intermediate" % cmddigest

pylib/gyp/generator/ninja.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,10 @@ def cygwin_munge(path):
809809
outputs = [self.GypPathToNinja(o, env) for o in outputs]
810810
if self.flavor == "win":
811811
# WriteNewNinjaRule uses unique_name to create a rsp file on win.
812-
extra_bindings.append(
813-
("unique_name", hashlib.md5(outputs[0]).hexdigest())
814-
)
812+
unique_name = hashlib.sha256(
813+
outputs[0].encode("utf-8")
814+
).hexdigest()
815+
extra_bindings.append(("unique_name", unique_name))
815816

816817
self.ninja.build(
817818
outputs,
@@ -2803,7 +2804,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
28032804
build_file, name, toolset
28042805
)
28052806
qualified_target_for_hash = qualified_target_for_hash.encode("utf-8")
2806-
hash_for_rules = hashlib.md5(qualified_target_for_hash).hexdigest()
2807+
hash_for_rules = hashlib.sha256(qualified_target_for_hash).hexdigest()
28072808

28082809
base_path = os.path.dirname(build_file)
28092810
obj = "obj"

pylib/gyp/xcodeproj_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def _HashUpdate(hash, data):
429429
hash.update(data)
430430

431431
if seed_hash is None:
432-
seed_hash = hashlib.sha1()
432+
seed_hash = hashlib.sha256()
433433

434434
hash = seed_hash.copy()
435435

0 commit comments

Comments
 (0)