Hello !<br><br>Here is a proposition for a patch for Erlang asn1 library. <br><br>I hope I didn't reimplement existing functionality, but I didn't manage to do it another way.<br><br>If the functionality is already implemented, thanks to reply me with some indication on how to proceed using it.<br>
<br>So this patch should be used to catch decoding error when the message to decode is incomplete and to return the error {error,incomplete} in this case. The existing behaviour is to throw various hard-to-match errors.<br>
<br>This change is necessary when using APER norm. The APER norm makes impossible to foresee the message length and so to foresee if the packet to decode is long enough to contain a full packet. So, when decoding a packet with error, it is impossible to say if it is because the contained message is incomplete or other. <br>
<br>With BER encoding it is cheap to read the size of the message, but with PER you have to decode the whole message first, so an in-library solution is better.<br><br>.diff file attached with the details of my modifications to add the return of the error {error,incomplete} in case of an incomplete message.<br>
<br>In the following files : <br> asn1rt_ber_bin.erl<br> asn1rt_ber_bin_v2.erl<br> asn1rt_uper_bin.erl<br> asn1rt_per_bin.erl<br> asn1rt_per_bin_rt2ct.erl<br>the size of the buffer put in argument should be check each time a function wants to match a precise number of bytes (related to an expected size of message).<br>
<br>This means <br>* to add a check_bit_size(Buffer,BitSize) or a check_bin_size(Buffer,BinSize) each time we had something like "<<Bin:5/binary,Rest/binary>> = Buffer",<br>* and to add pattern functions, for example: for getbit(Bin) we must add getbit(<<>>) -> throw({error,incomplete}) and not let the system crashed.<br>
<br>Note that check_bit_size/2 et check_bin_size/2 are functions added in each file.<br><br>Eventually, in the generator file asn1ct_gen.erl, just 2 lines in decode_disp/2 must be added to forward the error {error,incomplete} to the parent module.<br>
<br>This seems to be enough to implement the error matching, I tried to test with my data and it works and with bad data, it replies with an error {error,incomplete}.<br><br>What do you think about it ?<br><br>Best regards,<br>
Aude.<br><br>-- <br>Aude Quintana<br>