Skip to content

fix: replace weak hash functions with SHA-256 #3168

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions gyp/pylib/gyp/MSVSNew.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def MakeGuid(name, seed="msvs_new"):

Args:
name: Target name.
seed: Seed for MD5 hash.
seed: Seed for SHA-256 hash.
Returns:
A GUID-line string calculated from the name and seed.

Expand All @@ -44,8 +44,8 @@ def MakeGuid(name, seed="msvs_new"):
determine the GUID to refer to explicitly. It also means that the GUID will
not change when the project for a target is rebuilt.
"""
# Calculate a MD5 signature for the seed and name.
d = hashlib.md5((str(seed) + str(name)).encode("utf-8")).hexdigest().upper()
# Calculate a SHA-256 signature for the seed and name.
d = hashlib.sha256((str(seed) + str(name)).encode("utf-8")).hexdigest().upper()
# Convert most of the signature to GUID form (discard the rest)
guid = (
"{"
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

# Copy additional generator configuration data from Xcode, which is shared
# by the Mac Make generator.
import gyp.generator.xcode as xcode_generator

Check failure on line 81 in gyp/pylib/gyp/generator/make.py

View workflow job for this annotation

GitHub Actions / Lint Python

Ruff (PLC0415)

gyp/pylib/gyp/generator/make.py:81:9: PLC0415 `import` should be at the top-level of a file

global generator_additional_non_configuration_keys
generator_additional_non_configuration_keys = getattr(
Expand Down Expand Up @@ -2163,7 +2163,7 @@
# - The multi-output rule will have an do-nothing recipe.

# Hash the target name to avoid generating overlong filenames.
cmddigest = hashlib.sha1(
cmddigest = hashlib.sha256(
(command or self.target).encode("utf-8")
).hexdigest()
intermediate = "%s.intermediate" % cmddigest
Expand Down
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/generator/ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@
if self.flavor == "win":
# WriteNewNinjaRule uses unique_name to create a rsp file on win.
extra_bindings.append(
("unique_name", hashlib.md5(outputs[0]).hexdigest())
("unique_name", hashlib.sha256(outputs[0].encode("utf-8")).hexdigest())

Check failure on line 814 in gyp/pylib/gyp/generator/ninja.py

View workflow job for this annotation

GitHub Actions / Lint Python

Ruff (E501)

gyp/pylib/gyp/generator/ninja.py:814:89: E501 Line too long (95 > 88)
)

self.ninja.build(
Expand Down Expand Up @@ -1995,7 +1995,7 @@

# Copy additional generator configuration data from Xcode, which is shared
# by the Mac Ninja generator.
import gyp.generator.xcode as xcode_generator

Check failure on line 1998 in gyp/pylib/gyp/generator/ninja.py

View workflow job for this annotation

GitHub Actions / Lint Python

Ruff (PLC0415)

gyp/pylib/gyp/generator/ninja.py:1998:9: PLC0415 `import` should be at the top-level of a file

generator_additional_non_configuration_keys = getattr(
xcode_generator, "generator_additional_non_configuration_keys", []
Expand All @@ -2018,7 +2018,7 @@

# Copy additional generator configuration data from VS, which is shared
# by the Windows Ninja generator.
import gyp.generator.msvs as msvs_generator

Check failure on line 2021 in gyp/pylib/gyp/generator/ninja.py

View workflow job for this annotation

GitHub Actions / Lint Python

Ruff (PLC0415)

gyp/pylib/gyp/generator/ninja.py:2021:9: PLC0415 `import` should be at the top-level of a file

generator_additional_non_configuration_keys = getattr(
msvs_generator, "generator_additional_non_configuration_keys", []
Expand Down Expand Up @@ -2088,7 +2088,7 @@
return pool_size

if sys.platform in ("win32", "cygwin"):
import ctypes

Check failure on line 2091 in gyp/pylib/gyp/generator/ninja.py

View workflow job for this annotation

GitHub Actions / Lint Python

Ruff (PLC0415)

gyp/pylib/gyp/generator/ninja.py:2091:9: PLC0415 `import` should be at the top-level of a file

class MEMORYSTATUSEX(ctypes.Structure):
_fields_ = [
Expand Down Expand Up @@ -2811,7 +2811,7 @@
build_file, name, toolset
)
qualified_target_for_hash = qualified_target_for_hash.encode("utf-8")
hash_for_rules = hashlib.md5(qualified_target_for_hash).hexdigest()
hash_for_rules = hashlib.sha256(qualified_target_for_hash).hexdigest()

base_path = os.path.dirname(build_file)
obj = "obj"
Expand Down
6 changes: 3 additions & 3 deletions gyp/pylib/gyp/xcodeproj_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def _HashUpdate(hash, data):
hash.update(data)

if seed_hash is None:
seed_hash = hashlib.sha1()
seed_hash = hashlib.sha256()

hash = seed_hash.copy()

Expand All @@ -454,8 +454,8 @@ def _HashUpdate(hash, data):
child.ComputeIDs(recursive, overwrite, child_hash)

if overwrite or self.id is None:
# Xcode IDs are only 96 bits (24 hex characters), but a SHA-1 digest is
# is 160 bits. Instead of throwing out 64 bits of the digest, xor them
# Xcode IDs are only 96 bits (24 hex characters), but a SHA-256 digest is
# is 256 bits. Instead of throwing out bits of the digest, xor them
# into the portion that gets used.
assert hash.digest_size % 4 == 0
digest_int_count = hash.digest_size // 4
Expand Down
Loading