@@ -118,8 +118,8 @@ impl<'a> arbitrary::Arbitrary<'a> for &'a BytesRef {
118118pub ( crate ) mod allocating {
119119 use super :: BytesRef ;
120120 use crate :: {
121- DecodeValue , DerOrd , EncodeValue , EncodingRules , Error , Header , Length , Reader , Result ,
122- Tag , Writer , length:: indefinite:: read_constructed_vec,
121+ DecodeValue , DerOrd , EncodeValue , EncodingRules , Error , ErrorKind , Header , Length , Reader ,
122+ Result , Tag , Writer , length:: indefinite:: read_constructed_vec,
123123 } ;
124124 use alloc:: { borrow:: ToOwned , boxed:: Box , vec:: Vec } ;
125125 use core:: { borrow:: Borrow , cmp:: Ordering , ops:: Deref } ;
@@ -151,12 +151,23 @@ pub(crate) mod allocating {
151151 header : Header ,
152152 inner_tag : Tag ,
153153 ) -> Result < Self > {
154- // Reassemble indefinite length string types
155- if reader. encoding_rules ( ) == EncodingRules :: Ber
156- && header. length . is_indefinite ( )
157- && !inner_tag. is_constructed ( )
158- {
159- return Self :: new ( read_constructed_vec ( reader, header. length , inner_tag) ?) ;
154+ if header. is_constructed ( ) {
155+ if header. length . is_indefinite ( ) && reader. encoding_rules ( ) == EncodingRules :: Ber {
156+ // Reassemble indefinite length string types
157+ return Self :: new ( read_constructed_vec ( reader, header. length , inner_tag) ?) ;
158+ } else {
159+ // NOTE:
160+ // constructed strings with definite length unsupported
161+ // See discussion
162+ // - https://github.com/RustCrypto/formats/issues/779#issuecomment-3049869721
163+ //
164+ // NOTE: this repositions the error to be at the end of the header
165+ // rather than at the beginning of the value
166+ return Err ( Error :: new (
167+ ErrorKind :: Noncanonical { tag : header. tag } ,
168+ reader. position ( ) . saturating_sub ( Length :: ONE ) ,
169+ ) ) ;
170+ }
160171 }
161172
162173 Self :: decode_value ( reader, header)
0 commit comments