Skip to content
Draft
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
25 changes: 19 additions & 6 deletions src/Microsoft.DotNet.SignTool/src/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,20 @@ private FileSignInfo TrackFile(PathWithHash file, PathWithHash parentContainer,
{
// Only sign containers if the file itself is unsigned, or
// an item in the container is unsigned.
hasSignableParts = _zipDataMap[fileSignInfo.FileContentKey].NestedParts.Values.Any(b => b.FileSignInfo.SignInfo.ShouldSign || b.FileSignInfo.HasSignableParts);
if (hasSignableParts)
// Use TryGetValue to avoid KeyNotFoundException when DoNotUnpack skips adding to _zipDataMap
if (_zipDataMap.TryGetValue(fileSignInfo.FileContentKey, out var zipData))
{
// If the file has contents that need to be signed, then re-evaluate the signing info
fileSignInfo = fileSignInfo.WithSignableParts();
_filesByContentKey[fileSignInfo.FileContentKey] = fileSignInfo;
hasSignableParts = zipData.NestedParts.Values.Any(b => b.FileSignInfo.SignInfo.ShouldSign || b.FileSignInfo.HasSignableParts);
if (hasSignableParts)
{
// If the file has contents that need to be signed, then re-evaluate the signing info
fileSignInfo = fileSignInfo.WithSignableParts();
_filesByContentKey[fileSignInfo.FileContentKey] = fileSignInfo;
}
}
else
{
_log.LogError($"Container '{fileSignInfo.FullPath}' was not unpacked. Cannot determine signable parts. This may indicate an internal error in the signing logic.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you were saying that key not found was expected in some cases, yet this will error in that case.

}
}
if (fileSignInfo.ShouldTrack)
Expand Down Expand Up @@ -353,7 +361,12 @@ private FileSignInfo ExtractSignInfo(
// Hash doesn't exist so we use the CollisionPriorityId from the parent container
SignedFileContentKey parentSignedFileContentKey =
new SignedFileContentKey(parentContainer.ContentHash, parentContainer.FileName);
collisionPriorityId = _hashToCollisionIdMap[parentSignedFileContentKey];
// Use TryGetValue to avoid KeyNotFoundException when parent has DoNotUnpack flag
if (!_hashToCollisionIdMap.TryGetValue(parentSignedFileContentKey, out collisionPriorityId))
{
_log.LogError($"Unable to find collision priority ID for parent container '{parentContainer.FileName}' (hash: {parentContainer.ContentHash}) when processing nested file '{file.FileName}'. This may occur if the parent container was not properly tracked or had issues during processing.");
collisionPriorityId = string.Empty; // Use empty string as fallback
}
}
}

Expand Down
Loading