Skip to content

asn1c: preserve extensible SIZE constraints for PER#491

Open
acetcom wants to merge 1 commit intomouse07410:vlm_masterfrom
acetcom:fix-per-extensible-size-constraint
Open

asn1c: preserve extensible SIZE constraints for PER#491
acetcom wants to merge 1 commit intomouse07410:vlm_masterfrom
acetcom:fix-per-extensible-size-constraint

Conversation

@acetcom
Copy link
Copy Markdown

@acetcom acetcom commented Apr 30, 2026

Use the generic SIZE constraint range as a fallback when generating PER constraints for character string types such as UTF8String.

This preserves extensible constraints like SIZE(1..150, ...) as APC_CONSTRAINED | APC_EXTENSIBLE instead of falling back to APC_UNCONSTRAINED, avoiding APER decode failures for NGAP messages that depend on the extension bit layout.

@mouse07410
Copy link
Copy Markdown
Owner

mouse07410 commented Apr 30, 2026

@acetcom since I cannot modify PRs - please review and fix the CI failure. Also, please address the Copilot review suggestions.

Also, it might be a good idea to follow this:

If the fork owner has enabled "Allow edits from maintainers," you may be able to commit these individually even on a fork.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates PER constraint code generation to preserve extensible SIZE constraints for restricted character string types (e.g., UTF8String), preventing APER decoder failures caused by losing the extension bit layout when constraints degrade to unconstrained.

Changes:

  • Added a helper to detect when a PER-computed SIZE range is unusable and should fall back.
  • For restricted string types, falls back from asn1constraint_compute_PER_range() to the generic constraint range for ACT_CT_SIZE when needed, and forces PER visibility on the fallback range.

Comment thread libasn1compiler/asn1c_C.c
Comment on lines 3166 to +3202
range = asn1constraint_compute_PER_range(expr->Identifier, etype,
expr->combined_constraints, ACT_CT_SIZE, 0, 0, 0);

/*
* UTF8String (SIZE(lb..ub, ...)) has no PER-visible alphabet
* constraint, but its extensible size constraint is still PER-visible.
* Some inputs are reduced to an unconstrained PER range here, which
* makes the generated APER decoder miss the extension bit and fail to
* decode otherwise valid messages. Fall back to the generic constraint
* range only when the PER range has lost the size constraint.
*/
if((etype & ASN_STRING_MASK)
&& asn1c_per_range_needs_generic_size_fallback(range)) {
asn1cnst_range_t *generic_range =
asn1constraint_compute_constraint_range(
expr->Identifier, etype, expr->combined_constraints,
ACT_CT_SIZE, 0, 0, 0);

if(generic_range
&& !generic_range->incompatible
&& !generic_range->empty_constraint
&& !(generic_range->left.type == ARE_MIN
&& generic_range->right.type == ARE_MAX)) {
/*
* The generic constraint range is not produced by
* asn1constraint_compute_PER_range(), so it can still carry
* not_PER_visible even though SIZE(lb..ub, ...) is exactly
* what PER needs for constrained length encoding.
*/
generic_range->not_PER_visible = 0;

if(range) asn1constraint_range_free(range);
range = generic_range;
} else {
if(generic_range) asn1constraint_range_free(generic_range);
}
}
Comment thread libasn1compiler/asn1c_C.c
Comment on lines +2780 to +2785
* emit_single_member_PER_constraint() can only emit a constrained
* PER size if both bounds are concrete values. Anything else will
* be printed as APC_UNCONSTRAINED, so try the generic SIZE range.
*/
if(range->left.type != ARE_VALUE || range->right.type != ARE_VALUE)
return 1;
Comment thread libasn1compiler/asn1c_C.c
Comment on lines +2780 to +2782
* emit_single_member_PER_constraint() can only emit a constrained
* PER size if both bounds are concrete values. Anything else will
* be printed as APC_UNCONSTRAINED, so try the generic SIZE range.
@acetcom acetcom force-pushed the fix-per-extensible-size-constraint branch from 93423ef to 139e09e Compare April 30, 2026 16:13
@acetcom
Copy link
Copy Markdown
Author

acetcom commented Apr 30, 2026

@mouse07410

Thanks. I updated the expected outputs for the affected tests and also adjusted the commit message.

Sukchan

@acetcom acetcom force-pushed the fix-per-extensible-size-constraint branch from 139e09e to 3e2c44c Compare April 30, 2026 21:56
@mouse07410
Copy link
Copy Markdown
Owner

@acetcom there's no way I'd merge a PR with failing CI. Also, I'd like to see Copilot's review addressed.

Use the generic SIZE constraint range as a fallback when generating PER
constraints for restricted character string types such as UTF8String.

This preserves constraints like SIZE(1..150, ...) as
APC_CONSTRAINED | APC_EXTENSIBLE instead of falling back to
APC_UNCONSTRAINED, avoiding APER decode failures for NGAP messages that
depend on the extension bit layout.

Update the affected expected outputs, mark an invalid PER test input as
PER-incompatible, and keep UTF8String random-fill output compatible with
PER SIZE constraints.
@acetcom acetcom force-pushed the fix-per-extensible-size-constraint branch from 3e2c44c to 7d79535 Compare May 1, 2026 01:13
@acetcom
Copy link
Copy Markdown
Author

acetcom commented May 1, 2026

@mouse07410

CI issues have been fixed and the pipeline is now passing.

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.

3 participants