fix(importer): skip files with missing yEnc segments instead of importing them corrupt (#681)#688
Merged
Merged
Conversation
…ting them corrupt (#681) When a multi-segment file could not be size-normalized, parseFile swallowed the error and imported the file anyway using the NZB's raw yEnc-encoded byte counts. Those encoded sizes produce wrong segment offsets and yield a corrupt media file. The trigger reported in #681: the part-size probe fetches a single segment; if that article returns 430 on the provider used, normalization fails for the whole file and the corrupt fallback path runs. Skip the file instead when normalization fails because a required segment is missing from all providers (errors.Is ErrArticleNotFound). The existing aggregation loop drops it and continues, so the rest of the release imports normally. A present-but-non-yEnc article (no usable part size) still falls back to the NZB-declared sizes, preserving long-standing behavior. The "known not found" branches in normalizeSegmentSizesWithYenc now wrap ErrArticleNotFound so detection is uniform across the fetch and pre-stat paths. Tests: add TestParseNzbSkipsFileThatFailsNormalization (430 -> file skipped, healthy file kept with normalized sizes) and TestParseNzbKeepsFileWhenYencHeaderUnavailable (present-but-no-yEnc -> kept). Update parser_parsenzb_test.go to serve realistic yEnc for healthy fixtures.
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.
What
Fixes #681. When a multi-segment file could not be size-normalized,
parseFileswallowed the error and imported the file anyway using the NZB's raw yEnc-encoded byte counts. Those encoded sizes produce wrong segment offsets → corrupt media file.Now: when normalization fails because a required segment is missing from all providers (
errors.Is(err, nntppool.ErrArticleNotFound)), the file is skipped. The existing aggregation loop drops it and continues, so the rest of the release imports normally.Why this scope
The reported trigger: the part-size probe fetches a single segment; if that article returns
430on the provider used, normalization fails for the whole file and the corrupt fallback runs. The corruption only happens when we'd fall back to encoded NZB sizes for a file we can't verify.The skip is intentionally scoped to not-found errors:
To make detection uniform, the "known not found" branches in
normalizeSegmentSizesWithYencnow wrapErrArticleNotFound(NonRetryableError.Unwrapletserrors.Istraverse the fetch path too).Changes
internal/importer/parser/parser.go— scoped skip-on-not-found inparseFile; not-found branches innormalizeSegmentSizesWithYencwrapErrArticleNotFound.internal/importer/parser/parser_skip_test.go(new):TestParseNzbSkipsFileThatFailsNormalization— a 430 on a needed segment skips that file; the healthy file is kept with normalized (decoded) sizes, not raw encoded values.TestParseNzbKeepsFileWhenYencHeaderUnavailable— present-but-no-yEnc article is not skipped.internal/importer/parser/parser_parsenzb_test.go— serve realistic yEnc for healthy single-segment fixtures.Reviewer notes
430from a provider that actually has the article but isn't tried for the body fetch would now drop the file rather than corrupt it — the safe outcome. Cross-provider / multi-segment-probe recovery of such files was deliberately deferred (separate, larger change).Verification
go test ./internal/importer/parser/... -race✅,go vet✅go test ./internal/importer/ -race(integration battery) ✅make→ exit 0, 0 failures ✅