otp
otp copied to clipboard
ASN.1 compiler not supporting AtNotation properly
Describe the bug ASN.1 compiler (asn1ct 5.0.16 as well as 5.0.19) has issues compiling modules which contains AtNotation. AtNotation is a way to access the fields within the object it is defined in.
Definition from ITU-T X.682:
10.7 A component relation constraint is applied using the associated table of an information object set and the following production:
ComponentRelationConstraint ::= "{" DefinedObjectSet "}" "{" AtNotation "," + "}"
AtNotation ::= "@" ComponentIdList |
"@" "." Level ComponentIdList
Level ::= "." Level | empty
ComponentIdList ::= identifier "." +
To Reproduce
Example ASN.1 file X682-error.asn1 follows:
X682-error {itu-t(0) recommendation(0) x(24) x682(682) errors(0) otpbug(1)}
-- Definition from ITU-T X.682 (https://www.itu.int/rec/T-REC-X.682-202102-I/en)
-- 10 Table constraints, including component relation constraints
DEFINITIONS
::=
BEGIN
ERROR-CLASS ::= CLASS
{
&category PrintableString (SIZE(1)),
&code INTEGER,
&Type
}
WITH SYNTAX {&category &code &Type}
ErrorSet ERROR-CLASS ::=
{
{"A" 1 INTEGER} |
{"A" 2 REAL} |
{"B" 1 CHARACTER STRING} |
{"B" 2 GeneralString}
}
ErrorReturn ::= SEQUENCE
{
errorCategory ERROR-CLASS.&category ({ErrorSet}) OPTIONAL,
errors SEQUENCE OF SEQUENCE
{
errorCode ERROR-CLASS.&code ({ErrorSet}{@errorCategory}),
errorInfo ERROR-CLASS.&Type ({ErrorSet}{@errorCategory,@.errorCode})
} OPTIONAL
}
END
1> asn1ct:compile("/home/seba/work/forks/bugs/AtNotation/asn1/X682-error.asn1", [{i,"/home/seba/work/forks/bugs/AtNotation/asngen"},verbose,noobj,ber,{outdir,"/home/seba/work/forks/bugs/AtNotation/asngen"},{i,"."},{i,"/home/seba/work/forks/bugs/AtNotation/asn1"}]).
Erlang ASN.1 compiler 5.0.16
Compiling: "/home/seba/work/forks/bugs/AtNotation/asn1/X682-error.asn1"
Options: [{i,"/home/seba/work/forks/bugs/AtNotation/asngen"},
verbose,noobj,ber,
{outdir,"/home/seba/work/forks/bugs/AtNotation/asngen"},
{i,"."},
{i,"/home/seba/work/forks/bugs/AtNotation/asn1"}]
Internal error: error:function_clause
[{asn1ct_check,extract_at_notation,
[[{outermost,[{'Externalvaluereference',32,'X682-error',errorCategory}]},
{innermost,[{'Externalvaluereference',32,'X682-error',errorCode}]}]],
[{file,"asn1ct_check.erl"},{line,5277}]},
{asn1ct_check,any_component_relation,5,
[{file,"asn1ct_check.erl"},{line,5155}]},
{asn1ct_check,get_simple_table_if_used,2,
[{file,"asn1ct_check.erl"},{line,5052}]},
{asn1ct_check,componentrelation_leadingattr,2,
[{file,"asn1ct_check.erl"},{line,4954}]},
{asn1ct_check,check_sequence,3,[{file,"asn1ct_check.erl"},{line,4389}]},
{asn1ct_check,check_type,3,[{file,"asn1ct_check.erl"},{line,2769}]},
{asn1ct_check,check_sequenceof,3,[{file,"asn1ct_check.erl"},{line,4513}]},
{asn1ct_check,check_type,3,[{file,"asn1ct_check.erl"},{line,2777}]}]
{error,{internal_error,{error,function_clause}}}
Expected behavior I expect this module to compile.
Affected versions 24.0.1, 25.0.4
Additional context
The reason I found is was that I was trying to compile an ASN.1 module from ETSI EN 301 140-1 V1.3.4 (1999-06)
This is a minimized real-world example, found in the wild.
IN-CS2-classes {
ccitt(0) identified-organization(4) etsi(0) inDomain(1) in-network(1) cs2(20)
modules(0) in-cs2-classes (4) version1(0)}
DEFINITIONS ::=
BEGIN
PARAMETERS-BOUND ::= CLASS
{
&minFCIbccCS2Length INTEGER,
&maxFCIbccCS2Length INTEGER
}
WITH SYNTAX
{
MINIMUM-FOR-FCI-BILLING-CHARGING-CS-TWO &minFCIbccCS2Length
MAXIMUM-FOR-FCI-BILLING-CHARGING-CS-TWO &maxFCIbccCS2Length
}
SupportedExtensions {PARAMETERS-BOUND : bound} EXTENSION ::=
{
firstExtension,
...
-- full set of network operator extensions –
}
ExtensionField {PARAMETERS-BOUND : bound} ::= SEQUENCE
{
type EXTENSION.&id ({SupportedExtensions {bound}}),
value [1] EXTENSION.&ExtensionType ({SupportedExtensions {bound}}{@type}),
...
}
END
I'm not entirely sure it is the same issue, but it seems related. Should I open another bug-report with this issue?
2> asn1ct:compile("/home/seba/work/forks/bugs/asn1-AtNotation/asn1/IN-CS2-classes.asn1", [{i,"/home/seba/work/forks/bugs/asn1-AtNotation/asngen"},verbose,noobj,ber,{outdir,"/home/seba/work/forks/bugs/asn1-AtNotat
ion/asngen"},{i,"."},{i,"/home/seba/work/forks/bugs/asn1-AtNotation/asn1"}]).
Erlang ASN.1 compiler 5.0.16
Compiling: "/home/seba/work/forks/bugs/asn1-AtNotation/asn1/IN-CS2-classes.asn1"
Options: [{i,"/home/seba/work/forks/bugs/asn1-AtNotation/asngen"},
verbose,noobj,ber,
{outdir,"/home/seba/work/forks/bugs/asn1-AtNotation/asngen"},
{i,"."},
{i,"/home/seba/work/forks/bugs/asn1-AtNotation/asn1"}]
IN-CS2-classes.asn1:30: syntax error before: '{'
{error,[{structured_error,{"IN-CS2-classes.asn1",30},
asn1ct_parser2,
{syntax_error,'{'}}]}
I think the second case with the IN-CS2-classes is a different problem and that spec is not complete. EXTENSIONis undefined.
Will look at the first problem only. Please report the second problem as a separate issue and try to provide a complete spec with a definition of EXTENSION.