asn1c: preserve extensible SIZE constraints for PER#491
asn1c: preserve extensible SIZE constraints for PER#491acetcom wants to merge 1 commit intomouse07410:vlm_masterfrom
Conversation
|
@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:
|
There was a problem hiding this comment.
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 forACT_CT_SIZEwhen needed, and forces PER visibility on the fallback range.
| 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); | ||
| } | ||
| } |
| * 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; |
| * 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. |
93423ef to
139e09e
Compare
|
Thanks. I updated the expected outputs for the affected tests and also adjusted the commit message. Sukchan |
139e09e to
3e2c44c
Compare
|
@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.
3e2c44c to
7d79535
Compare
|
CI issues have been fixed and the pipeline is now passing. |
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.