Skip to content

Fix PEM parsing resumption for empty labels - #135885

Merged
vcsjones merged 2 commits into
dotnet:mainfrom
vcsjones:fix-pem-find
Oct 15, 2026
Merged

vcsjones merged 2 commits into
dotnet:mainfrom
vcsjones:fix-pem-find

Conversation

@vcsjones

Copy link
Copy Markdown
Member

In #133137 we fixed parsing to continue parsing at a more optimal location to prevent attempts to re-parse content that we know in advance is going to fail.

The fix advanced state a little too far in the narrow case of a PEM having an empty label. Consider the following PEM:

-----BEGIN -----BEGIN TEST-----\nZm9v\n-----END TEST-----

Initially, this is parsed as the PreEB: -----BEGIN ----- which is valid empty label. The BEGIN TEST----- which immediately follows is invalid base64. Before this fix, it would attempt to resume parsing at BEGIN TEST-----\nZm9v\n-----END TEST-----. That wouldn't match because it resumed too far - it needs to resume where the "empty" label was initially found because the two PreEB's share a boundary.

The same fix needs to be applied when looking for the end.

Fixes #135845

@azure-pipelines

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

@vcsjones
vcsjones merged commit 2ab4df2 into dotnet:main Oct 15, 2026
85 of 88 checks passed
@vcsjones

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

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

@vcsjones

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

X509Certificate2Collection.ImportFromPem silently drops a certificate preceded by -----BEGIN

2 participants