Skip to content

Commit

Permalink
fix: convert CRLF to LF before creating target object
Browse files Browse the repository at this point in the history
This is because file hashes get calculated differently on Windows vs
Linux if line endings are first saved as LF then get converted to CRLF
on Windows. To resolve, normalize all line endings to LF.
  • Loading branch information
n-dusan committed Jan 3, 2025
1 parent 87394b1 commit 1a38bb3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions taf/tuf/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
yk = YubikeyMissingLibrary() # type: ignore

from taf.constants import DEFAULT_RSA_SIGNATURE_SCHEME
from taf.utils import default_backend, get_file_details, on_rm_error
from taf.utils import (
default_backend,
get_file_details,
on_rm_error,
normalize_file_line_endings,
)
from tuf.api.metadata import (
Metadata,
MetaFile,
Expand Down Expand Up @@ -711,8 +716,12 @@ def _create_target_object(
self, filesystem_path: str, target_path: str, custom: Optional[Dict]
) -> TargetFile:
"""
Creates a TUF target object, later used to update targets metadata
Creates a TUF target object, later used to update targets metadata.
It's first necessary to normalize file line endings (convert all line endings to unix style endings)
before adding a target objects due to hashes getting calculated differently when using CRLF vs LF line endings.
So we instead convert all to unix style endings.
"""
normalize_file_line_endings(filesystem_path)
data = Path(filesystem_path).read_text().encode()
target_file = TargetFile.from_data(
target_file_path=target_path,
Expand Down

0 comments on commit 1a38bb3

Please sign in to comment.