Browse Source

* don't hangt on corrupt gifs, exit loops at end of streams.
Fixes mantis #34919

git-svn-id: trunk@40995 -

marco 6 years ago
parent
commit
6cc8ed3256
1 changed files with 13 additions and 3 deletions
  1. 13 3
      packages/fcl-image/src/fpreadgif.pas

+ 13 - 3
packages/fcl-image/src/fpreadgif.pas

@@ -211,7 +211,10 @@ begin
     // skip extensions
     // skip extensions
     Repeat
     Repeat
       Introducer:=SkipBlock(Stream);
       Introducer:=SkipBlock(Stream);
-    until (Introducer = $2C) or (Introducer = $3B);
+    until (Introducer = $2C) or (Introducer = $3B) or (Stream.Position>=Stream.Size);
+    
+    if Stream.Position>=Stream.Size then 
+      Exit;
 
 
     // descriptor
     // descriptor
     Stream.Read(FDescriptor, SizeOf(FDescriptor));
     Stream.Read(FDescriptor, SizeOf(FDescriptor));
@@ -298,7 +301,10 @@ begin
         Stream.Seek(B, soFromCurrent);
         Stream.Seek(B, soFromCurrent);
         CodeMask := (1 shl CodeSize) - 1;
         CodeMask := (1 shl CodeSize) - 1;
       end;
       end;
-    until B = 0;
+    until (B = 0)  or (Stream.Position>=Stream.Size);
+    
+    if Stream.Position>=Stream.Size then 
+      Exit(False);
 
 
     Progress(psRunning, trunc(100.0 * (Stream.position / Stream.size)),
     Progress(psRunning, trunc(100.0 * (Stream.position / Stream.size)),
              False, Rect(0,0,0,0), '', ContProgress);
              False, Rect(0,0,0,0), '', ContProgress);
@@ -315,7 +321,11 @@ begin
          Stream.ReadBuffer(SourcePtr^, B);
          Stream.ReadBuffer(SourcePtr^, B);
          Inc(SourcePtr,B);
          Inc(SourcePtr,B);
       end;
       end;
-    until B = 0;
+    until (B = 0) or (Stream.Position>=Stream.Size);
+    
+    if Stream.Position>=Stream.Size then
+       Exit(False);
+              
 
 
     Progress(psRunning, trunc(100.0 * (Stream.position / Stream.size)),
     Progress(psRunning, trunc(100.0 * (Stream.position / Stream.size)),
              False, Rect(0,0,0,0), '', ContProgress);
              False, Rect(0,0,0,0), '', ContProgress);