From 53b4bd019fe6b34559da1ce9c92533c9f79301ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 28 Mar 2016 20:52:14 +0200 Subject: NOISSUE fix bug in unpacking of forge pack200 jar files This caused failed downloads and broken files to be used. --- logic/java/JavaChecker.cpp | 1 - logic/minecraft/forge/ForgeXzDownload.cpp | 20 ++++++++++++++++++-- logic/net/CacheDownload.cpp | 5 ++++- logic/net/HttpMetaCache.cpp | 1 - logic/net/NetAction.h | 6 +----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/logic/java/JavaChecker.cpp b/logic/java/JavaChecker.cpp index dfda464f..54d552a9 100644 --- a/logic/java/JavaChecker.cpp +++ b/logic/java/JavaChecker.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include diff --git a/logic/minecraft/forge/ForgeXzDownload.cpp b/logic/minecraft/forge/ForgeXzDownload.cpp index 2a47bb26..adf96552 100644 --- a/logic/minecraft/forge/ForgeXzDownload.cpp +++ b/logic/minecraft/forge/ForgeXzDownload.cpp @@ -143,6 +143,7 @@ void ForgeXzDownload::downloadReadyRead() #include "xz.h" #include "unpack200.h" #include +#include const size_t buffer_size = 8196; @@ -275,7 +276,14 @@ void ForgeXzDownload::decompressAndInstall() failAndTryNextMirror(); return; } - FILE * file_in = fdopen(handle_in,"r"); + int handle_in_dup = dup (handle_in); + if(handle_in_dup == -1) + { + qCritical() << "Error reopening " << pack200_file.fileName(); + failAndTryNextMirror(); + return; + } + FILE *file_in = fdopen (handle_in_dup, "rb"); if(!file_in) { qCritical() << "Error reopening " << pack200_file.fileName(); @@ -296,7 +304,14 @@ void ForgeXzDownload::decompressAndInstall() failAndTryNextMirror(); return; } - FILE * file_out = fdopen(handle_out,"w"); + int handle_out_dup = dup (handle_out); + if(handle_out_dup == -1) + { + qCritical() << "Error reopening " << qfile_out.fileName(); + failAndTryNextMirror(); + return; + } + FILE *file_out = fdopen (handle_out_dup, "wb"); if(!file_out) { qCritical() << "Error opening " << qfile_out.fileName(); @@ -305,6 +320,7 @@ void ForgeXzDownload::decompressAndInstall() } try { + // NOTE: this takes ownership of both FILE pointers. That's why we duplicate them above. unpack_200(file_in, file_out); } catch (std::runtime_error &err) diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp index d79feb14..1ac55180 100644 --- a/logic/net/CacheDownload.cpp +++ b/logic/net/CacheDownload.cpp @@ -182,8 +182,11 @@ void CacheDownload::downloadReadyRead() { qCritical() << "Failed writing into " + m_target_path; m_status = Job_Failed; - m_reply->abort(); + m_output_file->cancelWriting(); + m_output_file.reset(); emit failed(m_index_within_job); + wroteAnyData = false; + return; } wroteAnyData = true; } diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp index 68bfa89c..ea3e2834 100644 --- a/logic/net/HttpMetaCache.cpp +++ b/logic/net/HttpMetaCache.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/logic/net/NetAction.h b/logic/net/NetAction.h index 1d7eb94b..3c395605 100644 --- a/logic/net/NetAction.h +++ b/logic/net/NetAction.h @@ -32,7 +32,7 @@ enum JobStatus }; typedef std::shared_ptr NetActionPtr; -class MULTIMC_LOGIC_EXPORT NetAction : public QObject, public std::enable_shared_from_this +class MULTIMC_LOGIC_EXPORT NetAction : public QObject { Q_OBJECT protected: @@ -54,10 +54,6 @@ public: { return m_failures; } - NetActionPtr getSharedPtr() - { - return shared_from_this(); - } public: /// the network reply -- cgit v1.2.3