File tree Expand file tree Collapse file tree 4 files changed +26
-0
lines changed 
src/ImageSharp/Formats/Gif Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -414,6 +414,11 @@ private void ReadComments(BufferedReadStream stream)
414414                GifThrowHelper . ThrowInvalidImageContentException ( $ "Gif comment length '{ length } ' exceeds max '{ GifConstants . MaxCommentSubBlockLength } ' of a comment data block") ; 
415415            } 
416416
417+             if  ( length  ==  - 1 ) 
418+             { 
419+                 GifThrowHelper . ThrowInvalidImageContentException ( "Unexpected end of stream while reading gif comment" ) ; 
420+             } 
421+ 
417422            if  ( this . skipMetadata ) 
418423            { 
419424                stream . Seek ( length ,  SeekOrigin . Current ) ; 
Original file line number Diff line number Diff line change @@ -381,4 +381,21 @@ public void Issue2859_LZWPixelStackOverflow<TPixel>(TestImageProvider<TPixel> pr
381381        image . DebugSaveMultiFrame ( provider ) ; 
382382        image . CompareToReferenceOutputMultiFrame ( provider ,  ImageComparer . Exact ) ; 
383383    } 
384+ 
385+     // https://github.com/SixLabors/ImageSharp/issues/2953 
386+     [ Theory ] 
387+     [ WithFile ( TestImages . Gif . Issues . Issue2953 ,  PixelTypes . Rgba32 ) ] 
388+     public  void  Issue2953 < TPixel > ( TestImageProvider < TPixel >  provider ) 
389+         where  TPixel  :  unmanaged,  IPixel < TPixel > 
390+     { 
391+         // We should throw a InvalidImageContentException when trying to identify or load an invalid GIF file. 
392+         TestFile  testFile  =  TestFile . Create ( provider . SourceFileOrDescription ) ; 
393+ 
394+         Assert . Throws < InvalidImageContentException > ( ( )  =>  Image . Identify ( testFile . FullPath ) ) ; 
395+         Assert . Throws < InvalidImageContentException > ( ( )  =>  Image . Load ( testFile . FullPath ) ) ; 
396+ 
397+         DecoderOptions  options  =  new ( )  {  SkipMetadata  =  true  } ; 
398+         Assert . Throws < InvalidImageContentException > ( ( )  =>  Image . Identify ( options ,  testFile . FullPath ) ) ; 
399+         Assert . Throws < InvalidImageContentException > ( ( )  =>  Image . Load ( options ,  testFile . FullPath ) ) ; 
400+     } 
384401} 
Original file line number Diff line number Diff line change @@ -581,6 +581,7 @@ public static class Issues
581581            public  const  string  Issue2866  =  "Gif/issues/issue_2866.gif" ; 
582582            public  const  string  Issue2859_A  =  "Gif/issues/issue_2859_A.gif" ; 
583583            public  const  string  Issue2859_B  =  "Gif/issues/issue_2859_B.gif" ; 
584+             public  const  string  Issue2953  =  "Gif/issues/issue_2953.gif" ; 
584585        } 
585586
586587        public  static readonly  string [ ]  Animated  = 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments