
# HG changeset patch
# User Fojtik
# Date 1668500646 -3600
# Node ID 5624f407b2f45f7f156b0808acee157de9c9b89e
# Parent  5163802a9e4d9d8ca437c27862e08eecae1622a0
Multiple frames in TGA file causes stack overflow - fixed.

--- wp2latex.git.orig/sources.cc/images/ras_img.cc
+++ wp2latex.git/sources.cc/images/ras_img.cc
@@ -3588,14 +3588,11 @@
 	   Raster=CreateRaster2D(x,y,i);
 	   binary=0;
 	   break;
-   case 3: x=atol(a);		//true color text
-	   y=ReadInt(f,&ch);
-	   i=ReadInt(f,&ch);
-	   Raster=CreateRaster2D(x,y,24);
-	   //p.typ:='C';
-	   //p.planes:=8;
-	   //p.x:=p.x * 3;
-	   binary=0;
+   case 3: x = atol(a);		//true color text
+	   y = ReadInt(f,&ch);
+	   i = ReadInt(f,&ch);
+	   Raster = CreateRaster2DRGB(x,y,8);
+	   binary = 0;
 	   break;
    case 4: x=atol(a);
 	   y=ReadInt(f,&ch);
@@ -3611,13 +3608,13 @@
 	   Raster=CreateRaster2D(x,y,8);
 	   binary=1;
 	   break;
-   case 6: x=atol(a);		//binary true color 24bit format
-	   y=ReadInt(f,&ch);
-	   i=ReadInt(f,&ch);
+   case 6: x = atol(a);		//binary true color 24bit format
+	   y = ReadInt(f,&ch);
+	   i = ReadInt(f,&ch);
 	   if(i!=255) goto ENDPROC;
 	   if(x<=0) goto ENDPROC;
-	   Raster=CreateRaster2D(x,y,24);
-	   binary=1;
+	   Raster = CreateRaster2DRGB(x,y,8);
+	   binary = 1;
 	   //p.typ='C';
 	   break;
    default: goto ENDPROC;
@@ -4790,7 +4787,8 @@
     // if AlineProc<>nil then AlineProc^.InitPassing(p.y,'Loading TGA');
     if(Header.ColorMapType==1)
     {
-      Palette=BuildPalette(1 << Header.ImagePixSize,8);
+      const long FilePos = ftell(f);
+      Palette = BuildPalette(1 << Header.ImagePixSize,8);
       if(Header.CMapEntrySize == 24)
       {		// Pozor Muze se zhroutit pri spatne tabulce
 	fread((char *)Palette->Data1D + 3*Header.CMapOrigin, 3*Header.CMapLength,1,f);
@@ -4807,7 +4805,7 @@
           Palette->B(y,(w&0x1F)<<3);
         }
       }
-      fseek(f,18+Header.IdentifLen + (Header.CMapEntrySize / 8)*Header.CMapLength,SEEK_SET);
+      fseek(f,FilePos + (Header.CMapEntrySize / 8)*Header.CMapLength,SEEK_SET);
     }
 
     // if(Header.ImageCodeType==ImagePalette) ColorMode=ImagePalette;
