Skip to content

Commit

Permalink
Fix: file corruption on x32 systems (#378)
Browse files Browse the repository at this point in the history
- fixed corruption of downloaded files on x32 architectures due to `segmentOffset` overflow and using `fseek` instead of `fseeko` function which can handle int64 width
  • Loading branch information
dnzbk authored Sep 10, 2024
1 parent e7ffa5f commit a59edac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions daemon/main/nzbget.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ typedef int pid_t;
#define FOPEN_WB "wb"
#define FOPEN_AB "ab"
#define CHILD_WATCHDOG 1
#define fseek fseeko

#endif /* POSIX */

Expand Down
13 changes: 9 additions & 4 deletions daemon/queue/DiskState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,12 @@ bool DiskState::SaveFileState(FileInfo* fileInfo, StateDiskFile& outfile, bool c
outfile.PrintLine("%i", (int)fileInfo->GetArticles()->size());
for (ArticleInfo* articleInfo : fileInfo->GetArticles())
{
outfile.PrintLine("%i,%u,%i,%u", (int)articleInfo->GetStatus(), (uint32)articleInfo->GetSegmentOffset(),
articleInfo->GetSegmentSize(), (uint32)articleInfo->GetCrc());
outfile.PrintLine("%i,%" PRIi64 ",%i,%u",
(int)articleInfo->GetStatus(),
articleInfo->GetSegmentOffset(),
articleInfo->GetSegmentSize(),
articleInfo->GetCrc()
);
}

outfile.Close();
Expand Down Expand Up @@ -1313,9 +1317,10 @@ bool DiskState::LoadFileState(FileInfo* fileInfo, Servers* servers, StateDiskFil

if (formatVersion >= 2)
{
uint32 segmentOffset, crc;
int64 segmentOffset;
uint32 crc;
int segmentSize;
if (infile.ScanLine("%i,%u,%i,%u", &statusInt, &segmentOffset, &segmentSize, &crc) != 4) goto error;
if (infile.ScanLine("%i,%" PRIi64 ",%i,%u", &statusInt, &segmentOffset, &segmentSize, &crc) != 4) goto error;
pa->SetSegmentOffset(segmentOffset);
pa->SetSegmentSize(segmentSize);
pa->SetCrc(crc);
Expand Down

0 comments on commit a59edac

Please sign in to comment.