Skip to content

fix(par2): SIMD-align slice size to prevent random AVX-512 segfaults#232

Merged
javi11 merged 1 commit into
mainfrom
session/practical-wilbur-c9be38
May 26, 2026
Merged

fix(par2): SIMD-align slice size to prevent random AVX-512 segfaults#232
javi11 merged 1 commit into
mainfrom
session/practical-wilbur-c9be38

Conversation

@javi11
Copy link
Copy Markdown
Owner

@javi11 javi11 commented May 26, 2026

Summary

Fixes the random signal: segmentation fault (core dumped) in the Coverage workflow
on internal/par2 (e.g. run 26437870974 / job 77824805140).

Root cause

createPar2ForFile only rounded the slice size to a 4-byte boundary (per the PAR2 spec)
before handing it to par2go. The ParPar C kernel on Linux x86_64 with AVX-512 reads in
64-byte vector lanes, so a non-aligned slice size (e.g. articleSize = 10_000
SliceSize = 10_000, which is 156 * 64 + 16) causes overreads past the slice buffer.

The crash only fires when the over-read happens to cross an unmapped page. That depends
on the allocator's run-to-run layout — flaky on Linux CI, never reproducible locally on
macOS / arm64 (different SIMD stride, and the existing 128-byte clamp happened to mask it).

The source already documented the requirement at par2.go:430-444, but the SIMD-safe
alignment guard was only applied when parBlockSize > file.Size. For the failing path
(SliceSize = 10MiB > file.Size = 100KB → fallback → articleSize = 10_000) the guard
was skipped entirely.

Fix

  • Extract per-file block-size policy into a testable computeFileBlockSize helper.
  • Make 128-byte SIMD alignment unconditional for every slice size handed to par2go
    (both createPar2ForFile and computeSetBlockSize).
  • Raise the "block too small" threshold from 4 to 128 and emit a clear "SIMD-safe"
    warning when skipping.
  • Add TestComputeFileBlockSize_SIMDAligned covering the CI repro case plus several
    edge cases; asserts result % 128 == 0 so we can't regress silently.

Test plan

  • go build ./internal/par2/...
  • go test -race -count=3 ./internal/par2/... — passes
  • TestComputeFileBlockSize_SIMDAligned covers the previously-crashing parameters
  • CI Coverage workflow goes green on Linux x86_64

The previous code only rounded the slice size to a 4-byte boundary (per the
PAR2 spec) before handing it to par2go. On Linux x86_64 with AVX-512 the
ParPar C kernel reads in 64-byte vector lanes, so non-aligned slice sizes
caused overreads past the slice buffer. The crash only fired when the
over-read happened to cross an unmapped page — flaky on CI, invisible
locally on macOS/arm64.

Extend the existing 128-byte SIMD alignment guard (previously only applied
when blockSize > fileSize) to every slice size handed to par2go, and extract
the per-file policy into a testable computeFileBlockSize helper.
@javi11 javi11 merged commit 2eec9f9 into main May 26, 2026
3 of 4 checks passed
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