From 6a03660fb252d92dddc4a69a92bf7b5edeaeca48 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 25 Nov 2018 15:31:40 +1100 Subject: [PATCH] Don't crash on too large skins --- ClassicalSharp/Entities/Player.cs | 6 +++--- src/Entity.c | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ClassicalSharp/Entities/Player.cs b/ClassicalSharp/Entities/Player.cs index f776d0328..b3a96061c 100644 --- a/ClassicalSharp/Entities/Player.cs +++ b/ClassicalSharp/Entities/Player.cs @@ -134,9 +134,9 @@ namespace ClassicalSharp.Entities { EnsurePow2(ref bmp); SkinType = Utils.GetSkinType(bmp); - if (SkinType == SkinType.Invalid) { - SetSkinAll(true); - } else { + if (bmp.Width > game.Graphics.MaxTexWidth || bmp.Height > game.Graphics.MaxTexHeight) { + game.Chat.Add("&cSkin " + SkinName + " is too large"); + } else if (SkinType != SkinType.Invalid) { if (Model.UsesHumanSkin) ClearHat(bmp, SkinType); TextureId = game.Graphics.CreateTexture(bmp, true, false); SetSkinAll(false); diff --git a/src/Entity.c b/src/Entity.c index f71d1bbf9..615d20939 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -715,7 +715,7 @@ static void Player_CheckSkin(struct Player* p) { } p->FetchedSkin = true; } - + if (!AsyncDownloader_Get(&skin, &item)) return; if (!item.ResultData) { Player_SetSkinAll(p, true); return; } Stream_ReadonlyMemory(&mem, item.ResultData, item.ResultSize); @@ -731,12 +731,10 @@ static void Player_CheckSkin(struct Player* p) { Player_EnsurePow2(p, &bmp); e->SkinType = Utils_GetSkinType(&bmp); - if (e->SkinType == SKIN_INVALID) { - Player_SetSkinAll(p, true); - } else { - if (e->Model->UsesHumanSkin) { - Player_ClearHat(&bmp, e->SkinType); - } + if (bmp.Width > Gfx_MaxTexWidth || bmp.Height > Gfx_MaxTexHeight) { + Chat_Add1("&cSkin %s is too large", &skin); + } else if (e->SkinType != SKIN_INVALID) { + if (e->Model->UsesHumanSkin) Player_ClearHat(&bmp, e->SkinType); e->TextureId = Gfx_CreateTexture(&bmp, true, false); Player_SetSkinAll(p, false); }