Skip to content

Read the cab signature from the correct reserved fields - #17363

Merged
nohwnd merged 2 commits into
dotnet:mainfrom
nohwnd:nohwnd-fix-signcheck-cab-signature
Aug 19, 2026
Merged

nohwnd merged 2 commits into
dotnet:mainfrom
nohwnd:nohwnd-fix-signcheck-cab-signature

Conversation

@nohwnd

@nohwnd nohwnd commented Aug 18, 2026

Copy link
Copy Markdown
Member

CabSecurityInfoProvider reads the signature offset and size from the wrong fields of the per-cabinet reserved area, so every signed .cab is reported as unsigned. The reserved area of a cab signed by signtool starts with a 0x00100000 header, and the offset and the size follow it. The provider skipped the header and read the offset from +0 and the size from +4, which puts signatureOffset + signatureSize past the end of the file, the bounds check fails, and ReadSecurityInfo returns null.

This reads the two fields from +4 and +8, requires the reserved area to be at least 12 bytes, and does the bounds check in long so a corrupt file cannot wrap around it.

Fix #17362

Verification

Added CabSecurityInfoProviderTests, it writes cabinets with the signtool reserved layout and a real PKCS#7 blob. ReadsSignatureFromTheSignedCabinetReservedArea fails with Assert.NotNull() Failure: Value is null on the current code and passes with this change. The other three cover a reserved area too small to hold the fields, a cabinet without a reserved area, and a file that is not a cabinet.

Also ran the fixed provider against two real signed cabs, IntelliTraceCollection.cab from Microsoft.Internal.Intellitrace 18.2.0-preview-1-11429-120 and the one from a VS 2022 Enterprise install. Both are now read correctly:

Subject: CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
Issuer:  CN=Microsoft Code Signing PCA 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

The first one is the file that fails signing validation in microsoft/vstest#16364.

To double check:

🤖

The per-cabinet reserved area of a signed cabinet starts with a 4 byte
header, and the signature offset and size follow it. CabSecurityInfoProvider
read the offset and the size from the first two fields, so it took the
header as the offset and the real offset as the size. The bounds check then
failed and every signed cab was reported as unsigned.

Fix dotnet#17362

Co-authored-by: Copilot App <[email protected]>
Copilot AI lite review requested due to automatic review settings August 18, 2026 14:48

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

Fixes CabSecurityInfoProvider so signed .cab / .msu files are correctly detected by reading the signature offset/size from the proper per-cabinet reserved-area fields (skipping the leading 0x00100000 header) and performing the bounds check in long to avoid overflow on corrupt inputs.

Changes:

  • Read signature offset/size from +4 / +8 of the per-cabinet reserved area and require a minimum reserved-area size of 12 bytes.
  • Use long arithmetic for signatureOffset + signatureSize bounds validation.
  • Add unit tests covering the signtool reserved layout and several negative cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Microsoft.DotNet.SignCheckLibrary/Verification/CabSecurityInfoProvider.cs Fixes reserved-area parsing and hardens bounds checking to correctly detect signed CABs.
src/Microsoft.DotNet.SignCheckLibrary.Tests/CabSecurityInfoProviderTests.cs Adds tests validating signature extraction for signtool-style CAB reserved layout and common failure modes.
Suppressed comments (1)

src/Microsoft.DotNet.SignCheckLibrary.Tests/CabSecurityInfoProviderTests.cs:127

  • Using BitConverter.GetBytes() writes values in the machine endianness; CAB headers are little-endian. To keep the test data deterministic across architectures, write the reserved fields explicitly as little-endian.
                byte[] reserve = new byte[reserveSize];
                if (reserveSize >= 4)
                {
                    BitConverter.GetBytes(0x00100000u).CopyTo(reserve, 0);
                }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@akoeplinger

Copy link
Copy Markdown
Member

LGTM, please take a look at the review comment from Copilot

BinaryWriter always writes little-endian but BitConverter.GetBytes uses the
machine endianness, so the test mixed the two. Cabinet fields are little-endian,
write them with BinaryPrimitives so the fixture is the same on every machine.

Also note why cbCabinet is the signature offset, it is the size of the cabinet
proper and signtool appends the signature after it. Both sample files agree.

Co-authored-by: Copilot App <[email protected]>
Copilot AI review requested due to automatic review settings August 19, 2026 10:53
@nohwnd

nohwnd commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

@akoeplinger looked at it, thanks. The cbCabinet comment is wrong, I replied on the thread with the numbers from two real signed cabs, cbCabinet is the size of the cabinet proper so in a signed cab it is exactly the signature offset, not the file size. Writing the file size there is what would make the fixture unrealistic.

The suppressed comment about BitConverter endianness was right, so I took that one, 04706e1 writes the reserved fields with BinaryPrimitives.WriteUInt32LittleEndian and documents why cbCabinet is the offset. Tests still pass.

🤖

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

src/Microsoft.DotNet.SignCheckLibrary/Verification/CabSecurityInfoProvider.cs:87

  • The per-cabinet reserved header is documented here as a fixed magic value (0x00100000), but the code reads and ignores it. That can cause false-positive signature detection for CABs that use the reserved area for other purposes. Consider validating the header value and returning null when it doesn't match the expected signed-CAB layout.
                    reader.ReadUInt32();                     // per-cabinet reserved header
                    uint signatureOffset = reader.ReadUInt32();
                    uint signatureSize = reader.ReadUInt32();

@nohwnd
nohwnd merged commit be5b996 into dotnet:main Aug 19, 2026
9 of 12 checks passed
@akoeplinger

Copy link
Copy Markdown
Member

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@akoeplinger

Copy link
Copy Markdown
Member

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@akoeplinger backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Read the cab signature from the correct reserved fields
Using index info to reconstruct a base tree...
A	src/Microsoft.DotNet.SignCheckLibrary/Verification/CabSecurityInfoProvider.cs
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): src/Microsoft.DotNet.SignCheckLibrary/Verification/CabSecurityInfoProvider.cs deleted in HEAD and modified in Read the cab signature from the correct reserved fields.  Version Read the cab signature from the correct reserved fields of src/Microsoft.DotNet.SignCheckLibrary/Verification/CabSecurityInfoProvider.cs left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Read the cab signature from the correct reserved fields
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@akoeplinger

Copy link
Copy Markdown
Member

@nohwnd please open a manual backport if you need it in release/10.0

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 20, 2026
nohwnd added a commit to nohwnd/vstest that referenced this pull request Aug 24, 2026
The Arcade fix dotnet/arcade#17363 is in 11.0.0-beta.26421.2, which main now consumes, so SignCheck reads the cab signature from the correct reserved fields and the exclusion is no longer needed.

Co-authored-by: Copilot App <[email protected]>
nohwnd added a commit to microsoft/vstest that referenced this pull request Aug 24, 2026
* Re-enable official signing validation

Co-authored-by: Copilot App <[email protected]>

* Exclude IntelliTraceCollection.cab from signing validation

The cab is signed by Microsoft, but SignCheck reads the signature offset
and size from the wrong offsets in the cabinet reserved area and reports
every signed cab as unsigned. Tracked by dotnet/arcade#17362, remove the
exclusion once the fix flows in.

Co-authored-by: Copilot App <[email protected]>

* Point the exclusion at the tracking issue

So whoever deletes the file knows what to close.

Co-authored-by: Copilot App <[email protected]>

* Remove the IntelliTraceCollection.cab signing exclusion

The Arcade fix dotnet/arcade#17363 is in 11.0.0-beta.26421.2, which main now consumes, so SignCheck reads the cab signature from the correct reserved fields and the exclusion is no longer needed.

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: Copilot App <[email protected]>
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.

SignCheck reports signed .cab files as unsigned

3 participants