Skip to content

Throw on truncated BER indefinite length encodings - #127

Merged
Lukasa merged 2 commits into
apple:mainfrom
Hashim1999164:throw-on-truncated-ber-indefinite
Aug 13, 2026
Merged

Lukasa merged 2 commits into
apple:mainfrom
Hashim1999164:throw-on-truncated-ber-indefinite

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #125

A truncated BER indefinite length constructed value was parsed as success. The last child was popped and treated as the end of contents marker, so that child disappeared.

The parser now throws truncatedASN1Field when input ends without those octets, matching X.690 section 8.1.3.6.1.

Test plan

Added testRejectsTruncatedBERIndefiniteLengthWithoutEndMarker. Built the SwiftASN1 product. Full XCTest suite needs Xcode.

Motivation:

A truncated BER indefinite length constructed value was treated as success. The last child was popped and used as the end of contents marker, which silently dropped data.

Modifications:

Require an end of contents marker after the indefinite length parse loop and throw truncatedASN1Field when it is missing. Add a regression test for the truncated and complete encodings.

Result:

Truncated BER indefinite length input fails instead of dropping the last child.
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Aug 13, 2026

@Lukasa Lukasa 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.

Thanks for this, this looks very nice!

@Lukasa
Lukasa enabled auto-merge (squash) August 13, 2026 14:19
@Lukasa
Lukasa merged commit d9a5b37 into apple:main Aug 13, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BER indefinite-length parser should throw on missing end-of-contents octets instead of silently dropping last child

2 participants