vlm / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
1.03k stars 553 forks source link

ETSI ITS DENM ReferenceDenms extension flag problem #290

Open MemoTrap opened 6 years ago

MemoTrap commented 6 years ago

I am working with asn1c for half a year meanwhile. It's an excellent tool. Many thanks for it.

I may have found a generator bug now. The (ETSI ITS) DENM ASN.1 spec (attached) has a definition:

ReferenceDenms ::= SEQUENCE SIZE (1..8, ...) OF ActionID

It carries the extension marker. ActionID is a sequence of two elements, a complex type. In this combination it appears to be the only one of this kind in the entire DENM ASN.1 spec (and the imported ITS Common spec, included as integrated part in the attachment here).

In the C code produced by the asn1c generator for PER constraints I get

asn_per_constraints_t asn_PER_type_ReferenceDenms_constr_1 CC_NOTUSED = {
    { APC_UNCONSTRAINED,    -1, -1,  0,  0 },
    { APC_CONSTRAINED,   3,  3,  1,  8 }    /* (SIZE(1..8)) */,
    0, 0    /* No PER value map */
};

I encoded with asn1c UPER and I tried to decode with http://asn1-playground.oss.com/ without success. ReferenceDenms (RoadworksContainer in AlacarteContainer) and everything hereafter is out of sync and asn1-playground reports an error.

I then manually added the extension flag:

asn_per_constraints_t asn_PER_type_ReferenceDenms_constr_1 CC_NOTUSED = {
    { APC_UNCONSTRAINED,    -1, -1,  0,  0 },
    { APC_CONSTRAINED | APC_EXTENSIBLE,  3,  3,  1,  8 }    /* (SIZE(1..8)) */,
    0, 0    /* No PER value map */
};

And now it all works, asn1-playground is happy.

ITS DENM v1.2.2.asn.zip

brchiu commented 6 years ago

Looks like function asn1constraint_pullup() calling _remove_extensions(arg, ct_expr, 1); removes extension part of constraint SIZE(1..8,...).

Though simply removing the calling of _remove_extensions(arg, ct_expr, 1); can add APC_EXTENSIBLE flag to asn_PER_type_ReferenceDenms_constr_1, it also break several regression tests when perform make check.

I don't have enough knowledge to verdict whether these regression tests need to be revised ? Or asn1constraint_pullup() should only call _remove_extensions(arg, ct_expr, 1); under certain condition ?

mouse07410 commented 6 years ago

@velichkov do you have any idea why it would ever make sense to remove extensions if they were specified?

@vlm any comment here?

Thanks!

brchiu commented 6 years ago

@mouse07410 , according to X.680, I.4.2.3 & I.4.4, there must be some conditions that extension additions are to be discarded, but related code logic might need be revised.

I.4.2.3
There are two key points in the serial application of constraints:
– If a constrained type is extensible (and perhaps extended), the "extensible" flag and all extension
additions are discarded if a further constraint is subsequently serially applied. The extensibility of a
constrained type (and any extension additions) depends solely on the last constraint that is applied, which
can reference only values in the root of the type that is being further constrained (the parent type). Values
included in the root or the extension additions of the resulting type can only be values that are in the root
of the parent type.
– The serial application of constraints is (for complex cases) not the same as a set arithmetic intersection,
even when there is no extensibility involved. Firstly, the environment in which MIN and MAX are
interpreted, and secondly the abstract values that can be referenced in the second constraint are very
different in serial application from the situation where the two constraints are specified as an intersection
of values from a common parent.

I.4.4
Use of the Contained Subtype notation
A contained subtype may or may not be extensible, but when it is used in set arithmetic it is always 
treated as not extensible, and all its extension additions are discarded.
mouse07410 commented 6 years ago

@brchiu the above seems to imply that the same ASN.1 file could produce encoding with member constraints either honored or dropped, depending on what format is used?

riebl commented 3 years ago

DENM v1.3.1 defines ReferenceDenms ::= SEQUENCE (SIZE(1..8, ...)) OF ActionID. Please note the additional parentheses around SIZE(1..8, ...) compared to the original definition given by @MemoTrap. Interestingly, asn1c seems to add APC_EXTENSIBLE only if these parentheses are present while other tools such as ffasn1c and https://asn1.io/asn1playground/ are less picky. To be honest, I don't know at the moment which one is right.