Repository navigation
fix(scoring): keep the default blood bonus when a stored value is out of range - #599
Open
Wangxiaolu0716 wants to merge 1 commit into
Open
Wangxiaolu0716 wants to merge 1 commit into
Wangxiaolu0716 wants to merge 1 commit into
Conversation
GZTimeWalker
approved these changes
Oct 15, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
BloodBonus是一个带主构造函数的 struct(src/GZCTF/Utils/Shared.cs:231)。越界分支里写的是new(),而 struct 的new()会零初始化,不会取init = DefaultValue:所以只要存进去的值超出每档
0..1000的范围,加成不是被夹紧、也不是保留默认值,而是被整段清零。之后GameRepository.cs:450会走noBonus分支,排行榜上所有血包加分都没了。能触发的输入:
Games.BloodBonus列在数据库里默认是0(bigint NOT NULL,见Migrations/20240202021414_Initialize.cs:153),存成 0 就会走FromValue的越界分支;PUT /api/Edit/Games/{id}里传一个超过 1000‰ 上限的BloodBonusValue(Game.cs:203);前端没有这个问题:那边的
new BloodBonus()依然返回(50 << 20) + (30 << 10) + 10(ClientApp/src/utils/Shared.tsx:492)。改动
BloodBonus.FromValue越界时回退到new(DefaultValue),一行。FlagChecker.GetWorkerCount()里的内存/CPU 分档挪进ResolveWorkerCount(memoryGiB, cpuCount),这样分档可以被单测覆盖。行为不变。src/GZCTF.Test/UnitTests/Models/ScoringTests.cs:动态计分曲线、血包位打包、worker 分档。这三块之前只有 HTTP 集成测试的间接覆盖。验证
dotnet test src/GZCTF.Test/GZCTF.Test.csproj -c Debug→ 179 passed。我把那一行改动还原回去跑过一次,确认测试真的能抓到这个 bug:
带上修复是 26/26 全过。没有 schema 变更。
关于 CI
Integration Tests这次跑到Build就失败了,原因是SixLabors.ImageSharp找不到 license:SixLaborsLicenseKey取的是secrets.SIXLABORS_LICENSE,而 fork 发起的 PR 拿不到仓库 secret,所以这一步在 fork PR 上必然失败;后面两个 test report 步骤因为找不到.trx也跟着报错。和本次改动无关。