fix(par2): skip PAR2 creation for files smaller than SIMD alignment#213
Merged
fix(par2): skip PAR2 creation for files smaller than SIMD alignment#213
Conversation
The par2go C backend may read up to (stride-1) bytes past the input buffer when the slice size isn't a multiple of the SIMD stride (64 B on AVX-512). PR #189 fixed this for files >=128 B by rounding the slice size down to a 128-byte boundary, but the else branch still fed sub-stride slices (e.g. 8 B for a 10-byte file) into the C library, causing intermittent segfaults on Linux x86_64 CI runners. Crashes were probabilistic because the overrun only segfaults when the read crosses into an unmapped page, which depends on heap layout, ASLR, and allocator state. Locally on macOS the SIMD path differs and the bug stays latent. Fix: skip PAR2 entirely for files <128 B (SIMD-safe alignment), matching the existing skip-with-warning pattern. Files that small yield no meaningful recovery data anyway, the upload pipeline already tolerates a nil par2 result, and the existing 10-byte regression test was written assuming "skip" is a valid outcome.
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.
Summary
Fixes intermittent CI segfault in
internal/par2:Root cause
The
par2goC backend may read up tostride-1bytes past the input buffer when the slice size isn't a multiple of the SIMD stride (64 B on AVX-512). PR #189 fixed this for files ≥128 B by rounding the slice size down to a 128-byte boundary, but theelsebranch still passed sub-stride slices (e.g. 8 B for a 10-byte file) to the C library, causing segfaults on Linux x86_64 CI runners.Crashes appeared "flaky" because the overrun only segfaults when the read crosses into an unmapped page — depends on heap layout, ASLR, and allocator state. The existing
defer recover()inTestIntegration_NativeExecutor_HandlesVerySmallFiles_10Bytescannot catch CGO segfaults (they bypass Go's panic mechanism). Locally on macOS the SIMD instruction path differs and the bug stays latent.Change
In
createPar2ForFile, whenparBlockSize > file.Sizeandfile.Size < 128, skip PAR2 creation with a warning instead of computing a sub-stride slice. Files that small yield no meaningful recovery data, and the upload pipeline already tolerates a nil par2 result (file upload runs in a parallel goroutine,poster.Post(ctx, nil, ...)is a no-op).The existing 10-byte regression test was already written assuming "skip" is a valid outcome (
"expect either a nil result (skipped with warning) or a graceful error, but never a panic").Test plan
go test -race -count=1 ./internal/par2/...passes locallyTestIntegration_NativeExecutor_HandlesVerySmallFiles_10Bytesnow takes the skip pathTestIntegration_NativeExecutor_HandlesVerySmallFiles_512Bytesstill creates PAR2 (≥128 B path unchanged)