Fix crash when tga image loader succeeds in loading a 0x0 image

Copy resource bitmaps before using them on a worker thread
This commit is contained in:
Magnus Norddahl 2020-03-19 15:46:04 +01:00
parent e19b2912f3
commit 44d972c876
4 changed files with 14 additions and 5 deletions

View file

@ -38,7 +38,7 @@ namespace CodeImp.DoomBuilder.Data
public BitmapImage(Bitmap img, string name) public BitmapImage(Bitmap img, string name)
{ {
// Initialize // Initialize
this.img = img; this.img = new Bitmap(img);
this.AllowUnload = false; this.AllowUnload = false;
SetName(name); SetName(name);
@ -62,7 +62,7 @@ namespace CodeImp.DoomBuilder.Data
// No failure checking here. I anything fails here, it is not the user's fault, // No failure checking here. I anything fails here, it is not the user's fault,
// because the resources this loads are in the assembly. // because the resources this loads are in the assembly.
return new LocalLoadResult(img); return new LocalLoadResult(new Bitmap(img));
} }
#endregion #endregion

View file

@ -165,10 +165,10 @@ namespace CodeImp.DoomBuilder.Data
data.Position += 9; // Skip some stuff... data.Position += 9; // Skip some stuff...
int width = data.ReadByte() + (data.ReadByte() << 8); int width = data.ReadByte() + (data.ReadByte() << 8);
if(width < 0 || width > 8192) return false; if(width <= 0 || width > 8192) return false;
int height = data.ReadByte() + (data.ReadByte() << 8); int height = data.ReadByte() + (data.ReadByte() << 8);
if(height < 0 || height > 8192) return false; if(height <= 0 || height > 8192) return false;
int bitsperpixel = data.ReadByte(); // Can be 8, 16, 24, 32 int bitsperpixel = data.ReadByte(); // Can be 8, 16, 24, 32
return (bitsperpixel == 8 || bitsperpixel == 16 || bitsperpixel == 24 || bitsperpixel == 32); return (bitsperpixel == 8 || bitsperpixel == 16 || bitsperpixel == 24 || bitsperpixel == 32);

View file

@ -39,7 +39,7 @@ namespace CodeImp.DoomBuilder.Data
// Initialize // Initialize
this.width = 0; this.width = 0;
this.height = 0; this.height = 0;
this.loadbitmap = Properties.Resources.UnknownImage; this.loadbitmap = new Bitmap(Properties.Resources.UnknownImage);
SetName(""); SetName("");
LoadImageNow(); LoadImageNow();

View file

@ -64,6 +64,9 @@ namespace CodeImp.DoomBuilder.IO
int width = rightMargin - leftMargin + 1; int width = rightMargin - leftMargin + 1;
int height = bottomMargin - topMargin + 1; int height = bottomMargin - topMargin + 1;
if (width == 0 || height == 0)
throw new InvalidDataException("Invalid pcx image file");
int vgaPaletteID = 0; int vgaPaletteID = 0;
byte[] vgaPalette = null; byte[] vgaPalette = null;
@ -250,6 +253,12 @@ namespace CodeImp.DoomBuilder.IO
if (colormap_type > 1) if (colormap_type > 1)
throw new InvalidDataException("Invalid or unsupported targa image file"); throw new InvalidDataException("Invalid or unsupported targa image file");
if (image_type != 1 && image_type != 2 && image_type != 3 && image_type != 9 && image_type != 10 && image_type != 11)
throw new InvalidDataException("Invalid or unsupported targa image type");
if (image_width == 0 || image_height == 0)
throw new InvalidDataException("Invalid targa image file");
if (colormap_type == 0) if (colormap_type == 0)
colormap_length = 0; colormap_length = 0;