From 9852cb9c9ea3793eaef405ebb671052bb4b6643a Mon Sep 17 00:00:00 2001 From: riperiperi Date: Fri, 20 Nov 2020 01:51:59 +0000 Subject: [PATCH] Use backup when PTC compression is corrupt (#1704) * Use backup when PTC compression is corrupt * Apply suggestions from code review Co-authored-by: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com> Co-authored-by: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com> --- ARMeilleure/Translation/PTC/Ptc.cs | 11 ++++++++++- ARMeilleure/Translation/PTC/PtcProfiler.cs | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs index 3baef401a6..c5cb123e44 100644 --- a/ARMeilleure/Translation/PTC/Ptc.cs +++ b/ARMeilleure/Translation/PTC/Ptc.cs @@ -196,7 +196,16 @@ namespace ARMeilleure.Translation.PTC { int hashSize = md5.HashSize / 8; - deflateStream.CopyTo(stream); + try + { + deflateStream.CopyTo(stream); + } + catch + { + InvalidateCompressedStream(compressedStream); + + return false; + } stream.Seek(0L, SeekOrigin.Begin); diff --git a/ARMeilleure/Translation/PTC/PtcProfiler.cs b/ARMeilleure/Translation/PTC/PtcProfiler.cs index dcc312750b..dbb3ed9d10 100644 --- a/ARMeilleure/Translation/PTC/PtcProfiler.cs +++ b/ARMeilleure/Translation/PTC/PtcProfiler.cs @@ -120,7 +120,16 @@ namespace ARMeilleure.Translation.PTC { int hashSize = md5.HashSize / 8; - deflateStream.CopyTo(stream); + try + { + deflateStream.CopyTo(stream); + } + catch + { + InvalidateCompressedStream(compressedStream); + + return false; + } stream.Seek(0L, SeekOrigin.Begin); @@ -264,4 +273,4 @@ namespace ARMeilleure.Translation.PTC } } } -} \ No newline at end of file +}