Skip to content

Fix issues from container build digest code review#55322

Draft
lbussell wants to merge 5 commits into
mainfrom
lbussell/sdk-container-build-digest-fixes
Draft

Fix issues from container build digest code review#55322
lbussell wants to merge 5 commits into
mainfrom
lbussell/sdk-container-build-digest-fixes

Conversation

@lbussell

Copy link
Copy Markdown
Member

This PR fixes Copilot's code review comments from #55301.

lbussell added 5 commits July 16, 2026 09:34
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 91cd6a00-c452-4c2b-b80a-b7f6784aeaff
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 91cd6a00-c452-4c2b-b80a-b7f6784aeaff
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 91cd6a00-c452-4c2b-b80a-b7f6784aeaff
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 91cd6a00-c452-4c2b-b80a-b7f6784aeaff
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 91cd6a00-c452-4c2b-b80a-b7f6784aeaff
Copilot AI review requested due to automatic review settings July 16, 2026 17:29
@lbussell
lbussell requested a review from a team as a code owner July 16, 2026 17:29
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR follows up on the container build digest-validation review by tightening resource cleanup and extending unit test coverage for digest mismatch scenarios in the container registry/layer code paths.

Changes:

  • Add unit tests to validate behavior when cached/downloaded blobs have invalid digests, and ensure temp artifacts are cleaned up.
  • Ensure temp files created during blob download and layer creation are cleaned up via finally blocks.
  • Minor logging template adjustment and removal of an unused digest helper.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/Microsoft.NET.Build.Containers.UnitTests/RegistryTests.cs Adds tests for redownloading cached blobs with invalid digests and rejecting downloaded blobs with invalid digests.
test/Microsoft.NET.Build.Containers.UnitTests/LayerTests.cs Adds a test to ensure temp files are deleted when Layer.FromDirectory fails.
src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs Ensures blob download temp file is cleaned up and improves cached-digest failure logging.
src/Containers/Microsoft.NET.Build.Containers/Layer.cs Ensures layer creation temp file is cleaned up on failure.
src/Containers/Microsoft.NET.Build.Containers/DigestUtils.cs Removes an unused internal hash-validation helper.

Comment on lines +179 to +183
writer.WriteEntry(entry);

if (entry.DataStream is not null)
{
// no longer relying on the `using` of the FileStream, so need to do it manually
entry.DataStream.Dispose();
}
if (entry.DataStream is not null)
{
// no longer relying on the `using` of the FileStream, so need to do it manually

// On Unix, we can determine the x-bit based on the filesystem permission.
// On Windows, we use executable permissions for all entries.
return (OperatingSystem.IsWindows() || ((file.UnixFileMode | UnixFileMode.UserExecute) != 0)) ? executeMode : nonExecuteMode;
Comment on lines +228 to +231
finally
{
File.Delete(tempTarballPath);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these try/catches for deletes are really bad whitespace-wise. maybe a structure that wraps a file-create in a Disposable so it can be deleted-on-leaving-scope in a clean way would be easier to read and use correctly without touching so much code?

Comment on lines +482 to +485
finally
{
File.Delete(tempTarballPath);
}
{
retryCount++;
if (retryCount >= MaxDownloadRetries)
catch (Exception ex)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will catch cancellation exceptions. Those should bubble up as-is.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree

{
// Incorrect digest
_logger.LogTrace(
"Digest validation failed for cached blob {1} ({2}), redownloading from registry.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this correct? I think this is using .NET's String.Format placeholders, which only accept numeric placeholders.

{
retryCount++;
if (retryCount >= MaxDownloadRetries)
catch (Exception ex)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree

Comment on lines +228 to +231
finally
{
File.Delete(tempTarballPath);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these try/catches for deletes are really bad whitespace-wise. maybe a structure that wraps a file-create in a Disposable so it can be deleted-on-leaving-scope in a clean way would be easier to read and use correctly without touching so much code?

}
finally
{
File.Delete(tempTarballPath);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

similar comment here: this is high-touch and a Disposable file would solve it more cleanly for review purposes.

@lbussell
lbussell marked this pull request as draft July 23, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants