From 92350e11c16bcf06c6bc94f9a028953f5cf63573 Mon Sep 17 00:00:00 2001 From: Martin Wilke Date: Mon, 10 May 2010 06:04:30 +0000 Subject: - Includes two patches * a bugfix that closes a memory leak triggered by corrupted PAR2 files. That fix is included in some linux vendors' libpar2 packages, and is well-tested. * The other adds additional functionality: a method to cancel a file repair in progress. This patch can be disabled through a config option. It is enabled by default because the only application in the ports tree that links against libpar2 is news/nzbget. Nzbget makes use of this functionality if it is available. PR: 146125 Submitted by: Jeff Burchell (maintainer) --- archivers/libpar2/Makefile | 12 +- archivers/libpar2/files/patch-ChangeLog | 10 +- archivers/libpar2/files/patch-par2repairer.cpp | 36 ++++ .../files/xpatch-addcancel-par2repairer.cpp | 194 +++++++++++++++++++++ 4 files changed, 247 insertions(+), 5 deletions(-) create mode 100644 archivers/libpar2/files/patch-par2repairer.cpp create mode 100644 archivers/libpar2/files/xpatch-addcancel-par2repairer.cpp (limited to 'archivers/libpar2') diff --git a/archivers/libpar2/Makefile b/archivers/libpar2/Makefile index 407d746626e6..c347c01c344a 100644 --- a/archivers/libpar2/Makefile +++ b/archivers/libpar2/Makefile @@ -7,7 +7,7 @@ PORTNAME= libpar2 PORTVERSION= 0.2 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= archivers MASTER_SITES= SF/parchive/${PORTNAME}/${PORTVERSION} DISTNAME= ${PORTNAME}-${PORTVERSION} @@ -24,10 +24,18 @@ CONFIGURE_ENV= LDFLAGS="-L${LOCALBASE}/lib" \ USE_LDCONFIG= yes +OPTIONS= ENABLECANCEL "Enable graceful cancellation of repairs" On + +.include + +.if defined(WITH_ENABLECANCEL) +EXTRA_PATCHES+= ${FILESDIR}/xpatch-addcancel-par2repairer.cpp +.endif + post-install: .if !defined(NOPORTDOCS) @${MKDIR} ${DOCSDIR} ${INSTALL_MAN} ${WRKSRC}/README ${DOCSDIR} .endif -.include +.include diff --git a/archivers/libpar2/files/patch-ChangeLog b/archivers/libpar2/files/patch-ChangeLog index 56b5a23ca6c8..d1385287a4d4 100644 --- a/archivers/libpar2/files/patch-ChangeLog +++ b/archivers/libpar2/files/patch-ChangeLog @@ -1,6 +1,10 @@ ---- ChangeLog.orig 2006-02-03 08:07:23.000000000 -0800 -+++ ChangeLog 2008-08-16 13:10:41.000000000 -0700 -@@ -1,3 +1,6 @@ +--- ChangeLog.orig 2010-04-28 12:17:05.000000000 -0700 ++++ ChangeLog 2010-04-28 12:16:35.000000000 -0700 +@@ -1,3 +1,10 @@ ++28 Apr 2010 FreeBSD Port ++ * Fix memory leak/segfault under certain circumstances. ++ http://sf.net/tracker/?func=detail&aid=2209433&group_id=30568&atid=399700 ++ +16 Aug 2008 FreeBSD Port + * Fix 2G overflow for data_size (backported from vendor CVS) + diff --git a/archivers/libpar2/files/patch-par2repairer.cpp b/archivers/libpar2/files/patch-par2repairer.cpp new file mode 100644 index 000000000000..ca1c844b7828 --- /dev/null +++ b/archivers/libpar2/files/patch-par2repairer.cpp @@ -0,0 +1,36 @@ +##### +# This patch is maintained by Andrei Prygounkov, author of news/nzbget +# It fixes a memory leak and a segfault triggered by a corrupted par2 file. +# +# For more details, see: +# http://sf.net/tracker/?func=detail&aid=2209433&group_id=30568&atid=399700 +##### +diff -aud ../libpar2-0.2-original/par2repairer.cpp ../libpar2-0.2/par2repairer.cpp +--- ../libpar2-0.2-original/par2repairer.cpp 2006-01-20 18:25:20.000000000 +0100 ++++ ../libpar2-0.2/par2repairer.cpp 2008-02-06 12:02:53.226050300 +0100 +@@ -78,6 +78,7 @@ + + delete mainpacket; + delete creatorpacket; ++ delete headers; + } + + +@@ -1261,7 +1262,7 @@ + DiskFile::SplitFilename(filename, path, name); + + cout << "Target: \"" << name << "\" - missing." << endl; +- sig_done.emit(name, 0, sourcefile->GetVerificationPacket()->BlockCount()); ++ sig_done.emit(name, 0, sourcefile->GetVerificationPacket() ? sourcefile->GetVerificationPacket()->BlockCount() : 0); + } + } + +@@ -1804,7 +1805,7 @@ + } + } + } +- sig_done.emit(name,count,sourcefile->GetVerificationPacket()->BlockCount()); ++ sig_done.emit(name,count, sourcefile->GetVerificationPacket() ? sourcefile->GetVerificationPacket()->BlockCount() : 0); + sig_progress.emit(1000.0); + return true; + } diff --git a/archivers/libpar2/files/xpatch-addcancel-par2repairer.cpp b/archivers/libpar2/files/xpatch-addcancel-par2repairer.cpp new file mode 100644 index 000000000000..be85aad127d0 --- /dev/null +++ b/archivers/libpar2/files/xpatch-addcancel-par2repairer.cpp @@ -0,0 +1,194 @@ +##### +# This patch is maintained by Andrei Prygounkov, author of news/nzbget +# It adds a graceful method to cancel file repair operations in progress. +# +# For more details, see: +# http://sf.net/tracker/?func=detail&aid=2209488&group_id=30568&atid=399700 +##### +diff -aud ../libpar2-0.2-original/par2repairer.cpp ../libpar2-0.2/par2repairer.cpp +--- ../libpar2-0.2-original/par2repairer.cpp 2008-10-26 19:54:33.000000000 +0100 ++++ ../libpar2-0.2/par2repairer.cpp 2008-10-29 10:24:48.000000000 +0100 +@@ -52,6 +52,8 @@ + noiselevel = CommandLine::nlNormal; + headers = new ParHeaders; + alreadyloaded = false; ++ ++ cancelled = false; + } + + Par2Repairer::~Par2Repairer(void) +@@ -406,6 +408,10 @@ + progress = offset; + sig_progress.emit(newfraction); + ++ if (cancelled) ++ { ++ break; ++ } + } + } + +@@ -584,6 +590,11 @@ + delete diskfile; + } + ++ if (cancelled) ++ { ++ return false; ++ } ++ + return true; + } + +@@ -833,9 +844,17 @@ + for (list::const_iterator s=files->begin(); s!=files->end(); ++s) + { + LoadPacketsFromFile(*s); ++ if (cancelled) ++ { ++ break; ++ } + } + + delete files; ++ if (cancelled) ++ { ++ return false; ++ } + } + + { +@@ -846,9 +865,17 @@ + for (list::const_iterator s=files->begin(); s!=files->end(); ++s) + { + LoadPacketsFromFile(*s); ++ if (cancelled) ++ { ++ break; ++ } + } + + delete files; ++ if (cancelled) ++ { ++ return false; ++ } + } + + return true; +@@ -866,9 +893,18 @@ + string::npos != filename.find(".PAR2")) + { + LoadPacketsFromFile(filename); ++ if (cancelled) ++ { ++ break; ++ } + } + } + ++ if (cancelled) ++ { ++ return false; ++ } ++ + return true; + } + +@@ -1210,6 +1246,11 @@ + sf = sortedfiles.begin(); + while (sf != sortedfiles.end()) + { ++ if (cancelled) ++ { ++ return false; ++ } ++ + // Do we have a source file + Par2RepairerSourceFile *sourcefile = *sf; + +@@ -1562,6 +1603,10 @@ + cout << "Scanning: \"" << shortname << "\": " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush; + sig_progress.emit(newfraction); + ++ if (cancelled) ++ { ++ break; ++ } + } + } + +@@ -1651,6 +1696,11 @@ + } + } + ++ if (cancelled) ++ { ++ return false; ++ } ++ + // Get the Full and 16k hash values of the file + filechecksummer.GetFileHashes(hashfull, hash16k); + +@@ -2291,10 +2341,19 @@ + cout << "Repairing: " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush; + sig_progress.emit(newfraction); + ++ if (cancelled) ++ { ++ break; ++ } + } + } + } + ++ if (cancelled) ++ { ++ break; ++ } ++ + ++inputblock; + ++inputindex; + } +@@ -2348,9 +2407,18 @@ + cout << "Processing: " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush; + sig_progress.emit(newfraction); + ++ if (cancelled) ++ { ++ break; ++ } + } + } + ++ if (cancelled) ++ { ++ break; ++ } ++ + ++copyblock; + ++inputblock; + } +@@ -2362,6 +2430,11 @@ + lastopenfile->Close(); + } + ++ if (cancelled) ++ { ++ return false; ++ } ++ + if (noiselevel > CommandLine::nlQuiet) + cout << "Writing recovered data\r"; + +diff -aud ../libpar2-0.2-original/par2repairer.h ../libpar2-0.2/par2repairer.h +--- ../libpar2-0.2-original/par2repairer.h 2006-01-20 00:38:27.000000000 +0100 ++++ ../libpar2-0.2/par2repairer.h 2008-10-26 19:01:08.000000000 +0100 +@@ -183,6 +183,7 @@ + u64 totaldata; // Total amount of data to be processed. + u64 totalsize; // Total data size + ++ bool cancelled; // repair cancelled + }; + + #endif // __PAR2REPAIRER_H__ -- cgit v1.2.3