@@ -732,13 +732,17 @@ pub(crate) struct LfnBuffer {
732732 ucs2_units : Vec < u16 > ,
733733}
734734
735+ const MAX_LONG_NAME_LEN : usize = 255 ;
736+
737+ const MAX_LONG_DIR_ENTRIES : usize = ( MAX_LONG_NAME_LEN + LFN_PART_LEN - 1 ) / LFN_PART_LEN ;
738+
735739#[ cfg( not( feature = "alloc" ) ) ]
736- const MAX_LFN_LEN : usize = 256 ;
740+ const LONG_NAME_BUFFER_LEN : usize = MAX_LONG_DIR_ENTRIES * LFN_PART_LEN ;
737741
738742#[ cfg( all( feature = "lfn" , not( feature = "alloc" ) ) ) ]
739743#[ derive( Clone ) ]
740744pub ( crate ) struct LfnBuffer {
741- ucs2_units : [ u16 ; MAX_LFN_LEN ] ,
745+ ucs2_units : [ u16 ; LONG_NAME_BUFFER_LEN ] ,
742746 len : usize ,
743747}
744748
@@ -777,14 +781,14 @@ impl LfnBuffer {
777781impl LfnBuffer {
778782 fn new ( ) -> Self {
779783 Self {
780- ucs2_units : [ 0_u16 ; MAX_LFN_LEN ] ,
784+ ucs2_units : [ 0_u16 ; LONG_NAME_BUFFER_LEN ] ,
781785 len : 0 ,
782786 }
783787 }
784788
785789 fn from_ucs2_units < I : Iterator < Item = u16 > > ( usc2_units : I ) -> Self {
786790 let mut lfn = Self {
787- ucs2_units : [ 0_u16 ; MAX_LFN_LEN ] ,
791+ ucs2_units : [ 0_u16 ; LONG_NAME_BUFFER_LEN ] ,
788792 len : 0 ,
789793 } ;
790794 for ( i, usc2_unit) in usc2_units. enumerate ( ) {
@@ -795,7 +799,7 @@ impl LfnBuffer {
795799 }
796800
797801 fn clear ( & mut self ) {
798- self . ucs2_units = [ 0_u16 ; MAX_LFN_LEN ] ;
802+ self . ucs2_units = [ 0_u16 ; LONG_NAME_BUFFER_LEN ] ;
799803 self . len = 0 ;
800804 }
801805
@@ -875,7 +879,7 @@ impl LongNameBuilder {
875879 fn process ( & mut self , data : & DirLfnEntryData ) {
876880 let is_last = ( data. order ( ) & LFN_ENTRY_LAST_FLAG ) != 0 ;
877881 let index = data. order ( ) & 0x1F ;
878- if index == 0 {
882+ if index == 0 || usize :: from ( index ) > MAX_LONG_DIR_ENTRIES {
879883 // Corrupted entry
880884 warn ! ( "currupted lfn entry! {:x}" , data. order( ) ) ;
881885 self . clear ( ) ;
0 commit comments