From 24be8c0814943b845ab3037d552d28f77ef8bbc9 Mon Sep 17 00:00:00 2001 From: BhaaL Date: Sat, 21 Jan 2017 21:26:19 +0100 Subject: [PATCH 1/3] IsGCZBlob: try to leave the file position where it was before callers that don't seek afterwards might be missing a few bytes that way. --- Source/Core/DiscIO/CompressedBlob.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index 0cf8dbc5b3..447088de61 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -410,8 +410,13 @@ bool DecompressBlobToFile(const std::string& infile_path, const std::string& out bool IsGCZBlob(File::IOFile& file) { + const u64 position = file.Tell(); + if (!file.Seek(0, SEEK_SET)) + return false; CompressedBlobHeader header; - return file.Seek(0, SEEK_SET) && file.ReadArray(&header, 1) && header.magic_cookie == GCZ_MAGIC; + bool is_gcz = file.ReadArray(&header, 1) && header.magic_cookie == GCZ_MAGIC; + file.Seek(position, SEEK_SET); + return is_gcz; } } // namespace From 30e0f3d9ca230b788efee736f6cb94d46fb8b925 Mon Sep 17 00:00:00 2001 From: BhaaL Date: Sat, 21 Jan 2017 21:27:25 +0100 Subject: [PATCH 2/3] DecompressFileToBlob: don't assume success if decompression failed --- Source/Core/DiscIO/CompressedBlob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index 447088de61..660bad7224 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -405,7 +405,7 @@ bool DecompressBlobToFile(const std::string& infile_path, const std::string& out outfile.Resize(header.data_size); } - return true; + return success; } bool IsGCZBlob(File::IOFile& file) From 07d1f18f5398d08149ded6a89028ce7953749bd3 Mon Sep 17 00:00:00 2001 From: BhaaL Date: Sat, 21 Jan 2017 21:27:25 +0100 Subject: [PATCH 3/3] CompressFileToBlob: add an explicit seek to make sure we're at the start --- Source/Core/DiscIO/CompressedBlob.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index 660bad7224..7c89121278 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -216,6 +216,8 @@ bool CompressFileToBlob(const std::string& infile_path, const std::string& outfi outfile.Seek(sizeof(CompressedBlobHeader), SEEK_CUR); // seek past the offset and hash tables (we will write them at the end) outfile.Seek((sizeof(u64) + sizeof(u32)) * header.num_blocks, SEEK_CUR); + // seek to the start of the input file to make sure we get everything + infile.Seek(0, SEEK_SET); // Now we are ready to write compressed data! u64 position = 0;