Skip to content

Fix: prevent SIGFPE crash in JoinFile when file segments are empty#772

Merged
dnzbk merged 1 commit intonzbgetcom:developfrom
MikeBlom:bugfix/fix-joinfile-divide-by-zero
Apr 5, 2026
Merged

Fix: prevent SIGFPE crash in JoinFile when file segments are empty#772
dnzbk merged 1 commit intonzbgetcom:developfrom
MikeBlom:bugfix/fix-joinfile-divide-by-zero

Conversation

@MikeBlom
Copy link
Copy Markdown
Contributor

@MikeBlom MikeBlom commented Apr 5, 2026

Description

Fixes #773 — a divide-by-zero crash (SIGFPE) in UnpackController::JoinFile() that occurs when split file segments (e.g., .7z.001, .7z.002) are zero-byte or corrupt.

When totalSize is calculated as 0 from empty fragments, the progress calculation on line 530:

m_postInfo->SetStageProgress(int(written * 1000 / totalSize));

triggers a SIGFPE, crashing NZBGet. Since NZBGet resumes post-processing on startup, this causes a crash loop that prevents the application from starting at all.

The fix adds a guard to return early with an error message when totalSize <= 0, preventing the divide-by-zero.

Lib changes

None.

Testing

  • Reproduced the crash on Arch Linux x86_64 with NZBGet v26.0 and v26.1-testing
  • Confirmed the crash occurs in UnpackController::JoinFile via coredumpctl info:
    Signal: 8 (FPE)
    #0  _ZN16UnpackController8JoinFileEPKc (/usr/bin/nzbget + 0xfcb94)
    #1  _ZN16UnpackController17JoinSplittedFilesEv (/usr/bin/nzbget + 0xfd0bd)
    
  • With the fix, NZBGet logs an error for the empty segments and continues running normally

When joining split files (e.g., .7z.001, .7z.002), totalSize is
calculated from fragment sizes. If all fragments are zero-byte or
corrupt, totalSize becomes 0 and the progress calculation
(written * 1000 / totalSize) triggers a divide-by-zero SIGFPE,
crashing nzbget on every startup as it resumes post-processing.

Add a guard to return early with an error message when totalSize <= 0.
@dnzbk dnzbk self-assigned this Apr 5, 2026
@dnzbk dnzbk self-requested a review April 5, 2026 14:17
@dnzbk dnzbk removed their assignment Apr 5, 2026
Copy link
Copy Markdown
Collaborator

@dnzbk dnzbk left a comment

Choose a reason for hiding this comment

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

Good catch, thank you

@dnzbk dnzbk merged commit 6e48519 into nzbgetcom:develop Apr 5, 2026
9 of 10 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.

SIGFPE crash in UnpackController::JoinFile when split file segments are empty

2 participants