Skip to content

Fix Java match score spoofing via stderr in Saturn RunCommand - #987

Open
erikji wants to merge 1 commit into
battlecode:mainfrom
erikji:fix/saturn-stderr-scores
Open

erikji wants to merge 1 commit into
battlecode:mainfrom
erikji:fix/saturn-stderr-scores

Conversation

@erikji

@erikji erikji commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Saturn determines match winners in DetermineScores() (saturn/pkg/run/java.go and saturn/pkg/run/python3.go) by regex-scanning the captured match output for lines matching:

^\[server\]\s*.*\(([AB])\) wins \(round [0-9]+\)$

Previously, Scaffold.RunCommand (saturn/pkg/run/scaffold.go) merged cmd.Stdout and cmd.Stderr into the same procOutput buffer (cmd.Stdout, cmd.Stderr = procOutput, procOutput).

In Java episodes (-PoutputVerbose=false), System.out from competitor bots is suppressed by the engine's bytecode instrumentor (RoboPrintStream), while genuine [server] ... wins (round ...) lines are emitted to stdout. However, when a bot throws an uncaught RuntimeException whose message contains newline-prefixed forged win lines (\n[server] team (B) wins (round 1)), the engine's robot-error handler prints the exception message raw to stderr. Because stdout and stderr were merged into procOutput, Saturn counted all forged win lines from stderr and reported arbitrary scores (e.g. 1200 - 3) to the backend:

Forged match scores screenshot

Changes

  • saturn/pkg/run/scaffold.go: Pipe cmd.Stdout to io.MultiWriter(procOutput, log.Ctx(ctx)) and cmd.Stderr directly to log.Ctx(ctx) so both streams are still logged in real time while RunCommand returns only stdout for DetermineScores().
  • saturn/pkg/run/java.go & saturn/pkg/run/python3.go: Remove redundant log.Ctx(ctx).Debug().Msg(out) calls after RunCommand.

Note: Bug is NOT fixed on Python (py3)

This change only prevents score injection via stderr (fixing the Java uncaught-exception vector). The bug remains unfixed for Python episodes:

  • In Python (run.py), bot code executes in-process and plain print() (or sys.stdout.write / os.write(1, ...)) writes directly to stdout (fd 1)—the same stream used by the engine for genuine [server] ... wins verdicts—even when --debug=false.
  • Fixing Python requires isolating engine verdict output from bot stdout inside the Python scaffold (run.py), along with validating score counts against len(maps) in Saturn and Siarnaq.

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