Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asn1 parameterized types with extension #4514

Closed
vances opened this issue Feb 14, 2021 · 3 comments
Closed

asn1 parameterized types with extension #4514

vances opened this issue Feb 14, 2021 · 3 comments
Labels
bug Issue is reported as a bug team:PO Assigned to OTP team PO

Comments

@vances
Copy link
Contributor

vances commented Feb 14, 2021

Describe the bug
Compilation of an ASN.1 module fails if it contains a parameterized type with an extension marker.

To Reproduce

T {}

DEFINITIONS ::= BEGIN

        Type {Type} ::= SEQUENCE {
                i Type, 
                ...
        }

        Instance ::= Type{INTEGER}

END
$ erlc T.asn1 
Internal error: error:function_clause
[{asn1ct_gen,do_gen_record_1,
             [[{'EXTENSIONMARK',14,undefined}]],
             [{file,"asn1ct_gen.erl"},{line,1277}]},
 {asn1ct_gen,do_gen_record_1,1,[{file,"asn1ct_gen.erl"},{line,1290}]},
 {asn1ct_gen,do_gen_record,3,[{file,"asn1ct_gen.erl"},{line,1271}]},
 {asn1ct_gen,gen_record,5,[{file,"asn1ct_gen.erl"},{line,1234}]},
 {asn1ct_gen,pgen_hrltypes,4,[{file,"asn1ct_gen.erl"},{line,1166}]},
 {asn1ct_gen,pgen_hrl,2,[{file,"asn1ct_gen.erl"},{line,1126}]},
 {asn1ct_gen,pgen,3,[{file,"asn1ct_gen.erl"},{line,69}]},
 {asn1ct,generate,4,[{file,"asn1ct.erl"},{line,855}]}]

Expected behavior
I am expecting the parameterized types to be ignored and encode/decode functions for other (simple) types to be generated.

Affected versions
Reproduced with Erlang/OTP 23 (asn1-5.0.8).

Additional context
The ASN.1 modules I am working with which highlighted this issue are in 3GPP TS 29.078 CAMEL Application Part (CAP).

@vances vances added the bug Issue is reported as a bug label Feb 14, 2021
@vances vances changed the title asn1 types parameterized by class with extension asn1 parameterized types with extension Feb 14, 2021
@IngelaAndin IngelaAndin added the team:PO Assigned to OTP team PO label Feb 15, 2021
@vances
Copy link
Contributor Author

vances commented Feb 16, 2021

I had been unclear about how extension markers were encoded but after empirical testing I can see that they are not encoded in BER. So the simple solution for my purposes becomes removing the ellipsis making this less of a bug and more a feature request.

T1 {}

DEFINITIONS ::= BEGIN

        With ::= SEQUENCE {
                i INTEGER,
                ...
        }

        Without ::= SEQUENCE {
                i INTEGER
        }

END
1> asn1ct:compile('T', [ber]).
ok
2> rr("T.hrl"). 
['With','Without']
3> {ok, With} = 'T':encode('With', #'With'{i = 42}), 
3> {ok, Without} = 'T':encode('Without', #'Without'{i = 42}),
3> With == Without.
true

@vances vances closed this as completed Feb 16, 2021
@KennethL
Copy link
Contributor

I have looked at this and I think it is a bug which we should fix. You are correct in that the extensionmarkers are not encoded, but they have significance when decoding data. If you decode a SEQUENCE which contains additional fields (after the extensionmarker) you decoder will accept it if there was an extensionmarker but will reject it if there is no extensionmarker (in your ASN.1 module which the decoder is generated from).

The original crash is when generating records and I think it is a bug to try to generate a record for a parameterized type at all.
I think the parameterized types should only be considered for generation of code when they are instantiated. But I have to check this further.

@KennethL KennethL reopened this Feb 16, 2021
KennethL added a commit that referenced this issue Apr 22, 2021
A parameterized type (SEQUENCE or SET) with an extension marker
made the compiler crash. The correction is to handle the
extensionmarker in the same way here as for non parameterized types.
GH-4514, OTP-17227
@KennethL
Copy link
Contributor

Fixed in OTP 23.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:PO Assigned to OTP team PO
Projects
None yet
Development

No branches or pull requests

3 participants