Skip to content

s2: Fix amd64 stack frame corruption#1145

Merged
klauspost merged 1 commit into
masterfrom
fix-s2-stack-pointer
Apr 30, 2026
Merged

s2: Fix amd64 stack frame corruption#1145
klauspost merged 1 commit into
masterfrom
fix-s2-stack-pointer

Conversation

@klauspost

@klauspost klauspost commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Fixes crash when pre-empted.

Fixes #1097 - see for analysis.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a low-level stack frame allocation issue on 64-bit systems to improve reliability.

Fixes crash when pre-empted.

Fixes #1097 - see for analysis.
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adjusted the frame size in the AMD64 assembly code for the s2Decode function by modifying the TEXT directive's frame and arguments parameters. This resolves a segmentation fault crash reported in s2.Decode operations.

Changes

Cohort / File(s) Summary
AMD64 Assembly Frame Size
s2/decode_amd64.s
Modified TEXT directive frame-args values for ·s2Decode function to correct stack frame size allocation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing amd64 stack frame corruption in s2 decode function.
Linked Issues check ✅ Passed The code change adjusts the Go assembler frame size for s2Decode on amd64, directly addressing the stack frame corruption crash reported in issue #1097.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the amd64 stack frame corruption in s2Decode; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-s2-stack-pointer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
s2/decode_amd64.s (1)

54-569: 🏗️ Heavy lift

Add a regression/stress test to prevent this asm+async-preemption crash from resurfacing.

Because the reported failure is specifically an async preemption SIGSEGV during s2.Decode on amd64, it would be good to add a targeted stress test that:

  • runs many concurrent decodes,
  • encourages async preemption (e.g., frequent scheduling/yield points and long-running loops),
  • and repeats enough times to catch rare stack-corruption failures.

Even a best-effort test (may be flaky unless tuned) would materially reduce risk for future asm changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@s2/decode_amd64.s` around lines 54 - 569, Add a targeted stress test that
repeatedly runs concurrent s2.Decode calls to reproduce async-preemption stack
corruption; create a test (e.g., TestDecodeAsyncPreemptStress) that spawns many
goroutines (N=hundreds), sets runtime.GOMAXPROCS>1, and in each goroutine loops
many times (thousands) calling s2.Decode on specially crafted inputs that
exercise long-running asm paths (long literal and copy sequences), interleaving
runtime.Gosched() or time.Sleep(0) to encourage async preemption and verifying
every Decode returns the expected result (no panic and correct error code); run
the test with short timeouts and allow tuning of goroutine/iteration counts so
CI can run a smaller default but maintain a heavy local/regression mode.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@s2/decode_amd64.s`:
- Around line 54-569: Add a targeted stress test that repeatedly runs concurrent
s2.Decode calls to reproduce async-preemption stack corruption; create a test
(e.g., TestDecodeAsyncPreemptStress) that spawns many goroutines (N=hundreds),
sets runtime.GOMAXPROCS>1, and in each goroutine loops many times (thousands)
calling s2.Decode on specially crafted inputs that exercise long-running asm
paths (long literal and copy sequences), interleaving runtime.Gosched() or
time.Sleep(0) to encourage async preemption and verifying every Decode returns
the expected result (no panic and correct error code); run the test with short
timeouts and allow tuning of goroutine/iteration counts so CI can run a smaller
default but maintain a heavy local/regression mode.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a061a31c-3a67-4bf0-92c0-06c61a455b28

📥 Commits

Reviewing files that changed from the base of the PR and between 1b63f2f and 329c017.

📒 Files selected for processing (1)
  • s2/decode_amd64.s

@klauspost klauspost merged commit 620d7b5 into master Apr 30, 2026
22 checks passed
@klauspost klauspost deleted the fix-s2-stack-pointer branch April 30, 2026 15:56
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.

Crash in s2.Decode

1 participant