From adeb48d5986b023777115c0350b7fe1ad77d08f1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 25 Oct 2024 07:54:49 +0200 Subject: [PATCH 1/6] Do a check if a local variable exceeds the available stack space. Windows stack is 1 MB so play it safe and allow 512 kb as max. stack space for a single function. --- src/common/scripting/backend/codegen.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index b14fb267c..df1c48c22 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -12640,6 +12640,15 @@ FxExpression *FxLocalVariableDeclaration::Resolve(FCompileContext &ctx) if (ValueType->RegType == REGT_NIL && ValueType != TypeAuto) { auto sfunc = static_cast(ctx.Function->Variants[0].Implementation); + + const unsigned MAX_STACK_ALLOC = 512 * 1024; // Windows stack is 1 MB, but we cannot go up there without problems + if (uint64_t(ValueType->Size) + uint64_t(sfunc->ExtraSpace) > MAX_STACK_ALLOC) + { + ScriptPosition.Message(MSG_ERROR, "%s exceeds max. allowed size of 512kb for local variables at variable %s", sfunc->Name.GetChars(), Name.GetChars()); + delete this; + return nullptr; + } + StackOffset = sfunc->AllocExtraStack(ValueType); if (Init != nullptr) From 2cbb980388786e88625f6b993065e998a46360ce Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 25 Oct 2024 08:47:19 +0200 Subject: [PATCH 2/6] Check array size for overflow. Since ZScript is a 32 bit VM, the largest safe value for an array's physical size is 2GB. Any larger value will be destroyed by the compiler which relies on signed 32 bit values too much. --- src/common/scripting/frontend/zcc_compile.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index d109717a3..faef50959 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -2286,6 +2286,11 @@ PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, Error(arraysize, "Array size must be positive"); return TypeError; } + if (uint64_t(size) * baseType->Size > 0x7fffffff) + { + Error(arraysize, "Array size overflow. Total size must be less than 2GB"); + return TypeError; + } baseType = NewArray(baseType, size); } From 3c36102eed62a6388c1bfc1a7d194630c0469496 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Fri, 25 Oct 2024 19:14:58 -0400 Subject: [PATCH 3/6] - cap the size of the string copy calls in LevelStatEntry() --- src/gamedata/statistics.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gamedata/statistics.cpp b/src/gamedata/statistics.cpp index 95d8165ae..d374f2e8a 100644 --- a/src/gamedata/statistics.cpp +++ b/src/gamedata/statistics.cpp @@ -343,8 +343,12 @@ static void LevelStatEntry(FSessionStatistics *es, const char *level, const char time (&clock); lt = localtime (&clock); - strcpy(s.name, level); - strcpy(s.info, text); + strncpy(s.name, level, sizeof(s.name) - 1); + s.name[sizeof(s.name) - 1] = '\0'; + + strncpy(s.info, text, sizeof(s.info) - 1); + s.info[sizeof(s.info) - 1] = '\0'; + s.timeneeded=playtime; es->levelstats.Push(s); } From dc6f11631534155de9f4324496c377cc9fbf995c Mon Sep 17 00:00:00 2001 From: "Dileep V. Reddy" Date: Sat, 26 Oct 2024 08:22:43 -0600 Subject: [PATCH 4/6] Reduce number of multiply ops per frame and increase x-axis clipper range for orthographic projection. --- src/rendering/hwrenderer/scene/hw_clipper.cpp | 4 ++-- src/rendering/r_utility.cpp | 4 ++++ src/rendering/r_utility.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_clipper.cpp b/src/rendering/hwrenderer/scene/hw_clipper.cpp index cef7b06b1..059a39981 100644 --- a/src/rendering/hwrenderer/scene/hw_clipper.cpp +++ b/src/rendering/hwrenderer/scene/hw_clipper.cpp @@ -476,8 +476,8 @@ angle_t Clipper::PointToPseudoOrthoAngle(double x, double y) { angle_t af = viewpoint->FrustAngle; double xproj = disp.XY().Length() * deltaangle(disp.Angle(), viewpoint->Angles.Yaw).Sin(); - xproj *= viewpoint->ScreenProj; - if (fabs(xproj) < r_viewwindow.WidescreenRatio*1.13) // 2.0) + xproj *= viewpoint->ScreenProjX; + if (fabs(xproj) < 1.13) { return AngleToPseudo( viewpoint->Angles.Yaw.BAMs() - xproj * 0.5 * af ); } diff --git a/src/rendering/r_utility.cpp b/src/rendering/r_utility.cpp index b7b6b452b..5313f738c 100644 --- a/src/rendering/r_utility.cpp +++ b/src/rendering/r_utility.cpp @@ -167,6 +167,7 @@ FRenderViewpoint::FRenderViewpoint() sector = nullptr; FieldOfView = DAngle::fromDeg(90.); // Angles in the SCREENWIDTH wide window ScreenProj = 0.0; + ScreenProjX = 0.0; TicFrac = 0.0; FrameTime = 0; extralight = 0; @@ -704,7 +705,10 @@ void FRenderViewpoint::SetViewAngle(const FViewWindow& viewWindow) HWAngles.Yaw = FAngle::fromDeg(270.0 - Angles.Yaw.Degrees()); if (IsOrtho() && (camera->ViewPos->Offset.XY().Length() > 0.0)) + { ScreenProj = 1.34396 / camera->ViewPos->Offset.Length() / tan (FieldOfView.Radians()*0.5); // [DVR] Estimated. +/-1 should be top/bottom of screen. + ScreenProjX = ScreenProj * 0.5 / viewWindow.WidescreenRatio; + } } diff --git a/src/rendering/r_utility.h b/src/rendering/r_utility.h index ca6d84b8c..f7e4a1e1d 100644 --- a/src/rendering/r_utility.h +++ b/src/rendering/r_utility.h @@ -43,6 +43,7 @@ struct FRenderViewpoint sector_t *sector; // [RH] keep track of sector viewing from DAngle FieldOfView; // current field of view double ScreenProj; // Screen projection factor for orthographic projection + double ScreenProjX; // Same for X-axis (screenspace) double TicFrac; // fraction of tic for interpolation uint32_t FrameTime; // current frame's time in tics. From b84d28e9a7ff61cd4d12468d994463a1e3cb7c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Fri, 25 Oct 2024 21:32:52 -0300 Subject: [PATCH 5/6] Allow using `Self` as the class name in the default block to refer to the current class --- src/scripting/zscript/zcc_compile_doom.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/scripting/zscript/zcc_compile_doom.cpp b/src/scripting/zscript/zcc_compile_doom.cpp index 3563967e5..a86ea9a0e 100644 --- a/src/scripting/zscript/zcc_compile_doom.cpp +++ b/src/scripting/zscript/zcc_compile_doom.cpp @@ -724,8 +724,15 @@ void ZCCDoomCompiler::ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt } else if (namenode->SiblingNext->SiblingNext == namenode) { + FName name(namenode->Id); + + if(name == NAME_self) + { + name = cls->TypeName; + } + // a two-name property - propname << FName(namenode->Id).GetChars() << "." << FName(static_cast(namenode->SiblingNext)->Id).GetChars(); + propname << name.GetChars() << "." << FName(static_cast(namenode->SiblingNext)->Id).GetChars(); } else { @@ -784,6 +791,13 @@ void ZCCDoomCompiler::ProcessDefaultFlag(PClassActor *cls, ZCC_FlagStmt *flg) else if (namenode->SiblingNext->SiblingNext == namenode) { // a two-name flag + + if(namenode->Id == NAME_self) + { + n1 = cls->TypeName.GetChars(); + } + + n2 = FName(static_cast(namenode->SiblingNext)->Id).GetChars(); } else From 0c29e3a77880f3519cf2908d340e114964aba38e Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Wed, 30 Oct 2024 16:22:33 -0500 Subject: [PATCH 6/6] Fixed STRETCHPIXELS flag not being exposed. --- src/scripting/thingdef_data.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index dc7fcacc3..cf1d0eca1 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -385,6 +385,7 @@ static FFlagDef ActorFlagDefs[]= DEFINE_FLAG(RF2, CAMFOLLOWSPLAYER, AActor, renderflags2), DEFINE_FLAG(RF2, ISOMETRICSPRITES, AActor, renderflags2), DEFINE_FLAG(RF2, SQUAREPIXELS, AActor, renderflags2), + DEFINE_FLAG(RF2, STRETCHPIXELS, AActor, renderflags2), // Bounce flags DEFINE_FLAG2(BOUNCE_Walls, BOUNCEONWALLS, AActor, BounceFlags),