Bound TAB and SPC padding to a byte - #125
Merged
Merged
Conversation
A single PRINT could allocate arbitrary memory: TAB and SPC built their padding with strings.Repeat over an unchecked argument, so `PRINT TAB(200000000)` reserved 206 MB of spaces and larger values scaled from there. Microsoft BASIC takes both arguments as a byte, so the authentic contract is 0 through 255 and a wider request is an illegal quantity. Reject anything outside that range with a diagnostic rather than honoring it. The comparison happens before the int conversion, because int() of an out-of-range float is undefined in Go and 1E30 would otherwise convert to a platform-dependent value. Truncation toward zero is unchanged, so SPC(255.9) still emits 255 spaces. No pinned corpus program exceeds the bound: the widest literal TAB is 60, and the smoke and gameplay tiers pass unchanged. Closes #122 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Closes #122.
Problem
TABandSPCbuilt their padding withstrings.Repeatover an unchecked argument, so a singlePRINTcould allocate arbitrary memory.Fix
Microsoft BASIC takes both arguments as a byte, so the authentic contract is
0through255and a wider request is an illegal quantity. This is a fidelity correction rather than an arbitrary cap.206 MB → 5.2 MB, which is just the Go runtime baseline.
Two details worth a look
int()conversion.int()of an out-of-range float is undefined in Go, soSPC(1E30)would otherwise convert to a platform-dependent value. The obvious ordering — convert, then range-check — is subtly wrong here.SPC(255.9)still emits 255 spaces. The comparison isargument >= maxPrintPadding+1for exactly this reason, rather than> maxPrintPadding.Risk
No pinned corpus program approaches the bound. The widest literal is
TAB(60):Computed arguments (
TAB(I),TAB(H/12+29),TAB((63-4.5*Y)) are covered by the gate: the smoke tier and the deterministic gameplay tier both pass unchanged, so nothing exceeds 255 at runtime either.Tests
TestEvaluatorAcceptsTabAndSpcAtTheByteBoundary— 255 still emits full padding for both.tab beyond line width/spc beyond line widthrows inTestEvaluatorReportsRuntimeErrors.Commands run
Full CI gate, green on the committed state:
🤖 Generated with Claude Code