Repository navigation
Read the cab signature from the correct reserved fields - #17363
Conversation
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]>
There was a problem hiding this comment.
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/+8of the per-cabinet reserved area and require a minimum reserved-area size of 12 bytes. - Use
longarithmetic forsignatureOffset + signatureSizebounds 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.
|
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]>
|
@akoeplinger looked at it, thanks. The The suppressed comment about 🤖 |
There was a problem hiding this comment.
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();
|
/backport to release/11.0 |
|
Started backporting to |
|
/backport to release/10.0 |
|
Started backporting to |
|
@akoeplinger backporting to 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 |
|
@nohwnd please open a manual backport if you need it in release/10.0 |
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]>
* 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]>
CabSecurityInfoProviderreads the signature offset and size from the wrong fields of the per-cabinet reserved area, so every signed.cabis reported as unsigned. The reserved area of a cab signed by signtool starts with a0x00100000header, and the offset and the size follow it. The provider skipped the header and read the offset from+0and the size from+4, which putssignatureOffset + signatureSizepast the end of the file, the bounds check fails, andReadSecurityInforeturns null.This reads the two fields from
+4and+8, requires the reserved area to be at least 12 bytes, and does the bounds check inlongso 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.ReadsSignatureFromTheSignedCabinetReservedAreafails withAssert.NotNull() Failure: Value is nullon 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.cabfromMicrosoft.Internal.Intellitrace18.2.0-preview-1-11429-120 and the one from a VS 2022 Enterprise install. Both are now read correctly:The first one is the file that fails signing validation in microsoft/vstest#16364.
To double check:
🤖