Skip to content

fix: prevent worldserver crash when saving oversized arena replays - #26

Merged
Helias merged 2 commits into
mainfrom
fix/save-replay-bytebuffer-overflow
Jun 20, 2026
Merged

Helias merged 2 commits into
mainfrom
fix/save-replay-bytebuffer-overflow

Conversation

@Helias

@Helias Helias commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

Problem

ArenaReplayBGScript::saveReplay serializes every recorded packet of a match into a single ArenaReplayByteBuffer. A long match (or one heavy on SMSG_UPDATE_OBJECT, which is in the watch list) accumulates enough data to push that buffer past the core's hard 10,000,000-byte sanity check in ByteBuffer::append:

ASSERT(size() < 10000000);

Acore::Assert calls Crash(), so the entire worldserver goes down at the end of the arena. Observed in the wild with a recording of ~190k packets:

#1 ByteBuffer::append (... message="size() < 10000000") ByteBuffer.cpp:114
#4 ArenaReplayBGScript::saveReplay (...) ArenaReplay.cpp:318
#5 ArenaReplayBGScript::OnBattlegroundEnd (...)
#7 Battleground::EndBattleground (...)

The DOT tick / kill that ends the match in the trace is incidental; any arena ending with a large enough recording crashes the same way.

Fix

Guard the serialization loop. Before each append, check whether writing the next packet (10-byte header + body) would reach the limit, and if so stop on the current packet boundary. Because the break happens between whole packets, the written stream stays well-framed and replays back correctly via the existing headerSize / timestamp / opcode reader. The replay is truncated instead of crashing the server.

A LOG_WARN records when truncation happens so oversized recordings are visible. Limit set to 9,000,000 to leave headroom under the 10 MB cap.

Notes / follow-ups

  • This stops the crash with no schema change. It does not preserve replays that exceed the limit (they are cut short) — splitting a replay across multiple rows would preserve them but needs a schema migration and load-path changes; out of scope here.
  • The deeper cause of the volume is SMSG_UPDATE_OBJECT in the watch list. Trimming it would shrink recordings substantially, at a fidelity cost; left for separate discussion.

Summary by CodeRabbit

  • Bug Fixes
    • Replay recording now enforces a maximum buffer size for saved replay data. When the limit is approached, a warning is logged and recording stops adding further packets, helping ensure the resulting replay remains well-formed and playable.

saveReplay serializes every recorded packet of a match into a single
ByteBuffer. A long match (or one heavy on SMSG_UPDATE_OBJECT) accumulates
enough data to push the buffer past ByteBuffer's hard 10,000,000-byte
ASSERT in append(), which calls Crash() and takes down the worldserver
at the end of the arena.

Guard the serialization loop: stop appending on a packet boundary once
the buffer would reach the limit, so the stream stays well-framed for
playback and the replay is truncated instead of crashing the server.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d36dd97-f879-4be0-8b1c-be3ff23d68ef

📥 Commits

Reviewing files that changed from the base of the PR and between df3a92f and 593be12.

📒 Files selected for processing (1)
  • src/ArenaReplay.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/ArenaReplay.cpp

📝 Walkthrough

Walkthrough

saveReplay in ArenaReplay.cpp gains a hard buffer cap (REPLAY_MAX_BUFFER_SIZE = 9,000,000 bytes). Before writing each packet, the code checks whether the next header plus payload would exceed this limit; if so, it emits a LOG_WARN and breaks out of the serialization loop. Log.h is added as a new include.

Changes

Replay serialization buffer cap

Layer / File(s) Summary
Buffer cap constant, Log.h include, and size check in saveReplay
src/ArenaReplay.cpp
Adds #include "Log.h", defines REPLAY_MAX_BUFFER_SIZE (9,000,000 bytes), and inserts a pre-write size check in the packet loop that calls LOG_WARN and breaks when the limit would be exceeded.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Hop, hop — the buffer won't bloat,
Nine million bytes, that's all she wrote!
A warning is logged, a loop snaps shut,
No overflow creeps past this fuzzy gut.
Safe replays saved, the arena's in tune~ ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically summarizes the main change: preventing worldserver crashes when saving oversized arena replays, which is the primary objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/save-replay-bytebuffer-overflow

Comment @coderabbitai help to get the list of available commands and usage tips.

@Helias
Helias merged commit 5fa897b into main Jun 20, 2026
2 checks passed
@Helias
Helias deleted the fix/save-replay-bytebuffer-overflow branch June 20, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant