@@ -65,6 +65,7 @@ enum UUValidatorState : byte
6565 long streamOffset ;
6666 int lineNumber ;
6767 UUValidatorState state ;
68+ bool invalidPretext ;
6869 byte nsaved ;
6970 byte uulen ;
7071
@@ -142,8 +143,11 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
142143
143144 // only lines containing whitespace are allowed before the begin marker
144145 while ( inptr < inend && * inptr != ( byte ) '\n ' ) {
145- if ( ! ( * inptr ) . IsWhitespace ( ) )
146- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset , lineNumber ) ;
146+ if ( ! invalidPretext && ! ( * inptr ) . IsWhitespace ( ) ) {
147+ // FIXME: should this really be emitted for *each* character before the 'begin'?
148+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset + ( int ) ( inptr - start ) , lineNumber ) ;
149+ invalidPretext = true ;
150+ }
147151
148152 inptr ++ ;
149153 }
@@ -154,10 +158,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
154158 return false ;
155159 }
156160
157- SkipByte ( ref inptr ) ;
158-
159161 streamOffset += ( int ) ( inptr - start ) ;
160162
163+ SkipByte ( ref inptr ) ;
164+
161165 if ( inptr == inend )
162166 return false ;
163167 }
@@ -166,7 +170,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
166170 if ( nsaved != ( byte ) 'b' ) {
167171 // only lines containing whitespace are allowed before the begin marker
168172 if ( ! nsaved . IsWhitespace ( ) ) {
169- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset , lineNumber ) ;
173+ if ( ! invalidPretext ) {
174+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset - 1 , lineNumber ) ;
175+ invalidPretext = true ;
176+ }
170177 state = UUValidatorState . ExpectBegin ;
171178 continue ;
172179 }
@@ -182,7 +189,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
182189 if ( state == UUValidatorState . B ) {
183190 nsaved = ReadByte ( ref inptr ) ;
184191 if ( nsaved != ( byte ) 'e' ) {
185- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset , lineNumber ) ;
192+ if ( ! invalidPretext ) {
193+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset - 1 , lineNumber ) ;
194+ invalidPretext = true ;
195+ }
186196 state = UUValidatorState . ExpectBegin ;
187197 continue ;
188198 }
@@ -195,7 +205,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
195205 if ( state == UUValidatorState . Be ) {
196206 nsaved = ReadByte ( ref inptr ) ;
197207 if ( nsaved != ( byte ) 'g' ) {
198- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset , lineNumber ) ;
208+ if ( ! invalidPretext ) {
209+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset - 1 , lineNumber ) ;
210+ invalidPretext = true ;
211+ }
199212 state = UUValidatorState . ExpectBegin ;
200213 continue ;
201214 }
@@ -208,7 +221,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
208221 if ( state == UUValidatorState . Beg ) {
209222 nsaved = ReadByte ( ref inptr ) ;
210223 if ( nsaved != ( byte ) 'i' ) {
211- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset , lineNumber ) ;
224+ if ( ! invalidPretext ) {
225+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset - 1 , lineNumber ) ;
226+ invalidPretext = true ;
227+ }
212228 state = UUValidatorState . ExpectBegin ;
213229 continue ;
214230 }
@@ -221,7 +237,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
221237 if ( state == UUValidatorState . Begi ) {
222238 nsaved = ReadByte ( ref inptr ) ;
223239 if ( nsaved != ( byte ) 'n' ) {
224- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset , lineNumber ) ;
240+ if ( ! invalidPretext ) {
241+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset - 1 , lineNumber ) ;
242+ invalidPretext = true ;
243+ }
225244 state = UUValidatorState . ExpectBegin ;
226245 continue ;
227246 }
@@ -234,7 +253,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
234253 if ( state == UUValidatorState . Begin ) {
235254 nsaved = ReadByte ( ref inptr ) ;
236255 if ( nsaved != ( byte ) ' ' ) {
237- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset , lineNumber ) ;
256+ if ( ! invalidPretext ) {
257+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodePretext , streamOffset - 1 , lineNumber ) ;
258+ invalidPretext = true ;
259+ }
238260 state = UUValidatorState . ExpectBegin ;
239261 continue ;
240262 }
@@ -296,9 +318,10 @@ unsafe bool ScanBeginMarker (ref byte* inptr, byte* inend)
296318 return false ;
297319 }
298320
321+ streamOffset += ( int ) ( inptr - start ) ;
322+
299323 SkipByte ( ref inptr ) ;
300324
301- streamOffset += ( int ) ( inptr - start ) ;
302325 state = UUValidatorState . Payload ;
303326 nsaved = 0 ;
304327
@@ -376,7 +399,7 @@ unsafe void Validate (byte* input, int length)
376399 }
377400 } else {
378401 // extra data beyond the end of the uuencoded line
379- reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodedLineLength , streamOffset , lineNumber ) ;
402+ reader . OnMimeComplianceViolation ( MimeComplianceViolation . InvalidUUEncodedLineLength , streamOffset - 1 , lineNumber ) ;
380403 }
381404 }
382405 }
0 commit comments