erlang / otp

Erlang/OTP
http://erlang.org
Apache License 2.0
11.43k stars 2.96k forks source link

ERL-594: asn1ct_check fails on external ptypespec #3200

Open OTP-Maintainer opened 6 years ago

OTP-Maintainer commented 6 years ago

Original reporter: roadrunnr71 Affected versions: OTP-20.2.1, OTP-20.3 Component: asn1 Migrated from: https://bugs.erlang.org/browse/ERL-594


When trying to compile the ASN.1 from 3GPP TS 32.298 (attached as tgz), the asn1ct_check failes with:

{code}
Internal error: error:{badrecord,typedef}
[{asn1ct_check,check_type,3,[{file,"asn1ct_check.erl"},{line,2549}]},
 {asn1ct_check,do_checkt,3,[{file,"asn1ct_check.erl"},{line,287}]},
 {asn1ct_check,check_fold,3,[{file,"asn1ct_check.erl"},{line,6074}]},
 {asn1ct_check,checkt,2,[{file,"asn1ct_check.erl"},{line,281}]},
 {asn1ct_check,check,2,[{file,"asn1ct_check.erl"},{line,92}]},
 {asn1ct,check_pass,1,[{file,"asn1ct.erl"},{line,202}]},
 {asn1ct,run_passes_1,2,[{file,"asn1ct.erl"},{line,285}]},
 {asn1ct,process,2,[{file,"asn1ct.erl"},{line,2399}]}]
{code}

It turns out that at https://github.com/erlang/otp/blob/master/lib/asn1/src/asn1ct_check.erl#L2549 the RefTypeDef is:

{code}
{ptypedef,false,522,'DestinationRoutingAddress',
                [{{type,[],
                      {'Externaltypereference',522,'CAP-classes',
                          'PARAMETERS-BOUND'},
                      [],[],no},
                  {'Externalvaluereference',522,'CAP-datatypes',bound}}],
                {type,[],
                    {'SEQUENCE OF',
                        {type,[],
                            {pt,{'Externaltypereference',523,'CAP-datatypes',
                                    'CalledPartyNumber'},
                                [{'Externalvaluereference',523,
                                     'CAP-datatypes',bound}]},
                            [],[],no}},
                    [{element_set,
                         {'SizeConstraint',
                             {element_set,{'SingleValue',1},none}},
                         none}]
{code}
OTP-Maintainer commented 6 years ago

kenneth said:

Which file are you compiling and with what options when the error above occurs?
Among the .asn1 modules you have sent there is imports from other ASN1 modules that you have not provided, like
for example CAP-classes imported from CAP-datatypes. So there is no chance that CAP-databases will be successfully compiled anyhow.
OTP-Maintainer commented 6 years ago

roadrunnr71 said:

I've attached a minimum project with all the ASN.1 files. There are multiple `Internal error: error:badarg` failures when trying to compile this.
OTP-Maintainer commented 6 years ago

roadrunnr71 said:

I managed to extract two minimal test cases. There might be more....
OTP-Maintainer commented 6 years ago

roadrunnr71 said:

I have found a fix for one of the problems (https://github.com/RoadRunnr/otp/commit/045418c604a8afcea3d718fbe9292e8eed7cbc19).

A small test ASN.1 is included, but I don't know (and don't have the time to investigate) how to hook it into the test suite.
OTP-Maintainer commented 6 years ago

kenneth said:

Just for my understanding. Your fix is fixing compilation of Test2.asn1 or ChoiceDefault.asn1?
What .asn1 file is now causing the remaining fault?

What parameters are you using towards the asn1 compiler?
OTP-Maintainer commented 6 years ago

roadrunnr71 said:

It is fixing the ChoiceDefault.asn1. Test2.asn1 still breaks.

No extra arguments, i'm just doing a ```asn1ct:compile("Test2.asn1").```

The remaining asn1 files still don't work. I'll try to extract a few more failing cases into simplified constructs.
OTP-Maintainer commented 6 years ago

roadrunnr71 said:

I've extracted a minimal test case for another failure from the full set of ASN.1 files.

This time asn1ct_constructed_per failes with ```Internal error: error:badarg```

https://github.com/RoadRunnr/otp/commit/420d9fe71bad58978a560480b36774644d2b775b