From 2299d8ed6e80f4fd61caa39500e57c78fab5920d Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 14 Sep 2018 05:40:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Don't=20read=20additional=2012?= =?UTF-8?q?=20bytes=20after=20each=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 074f395..f4ab5a6 100644 --- a/src/main.c +++ b/src/main.c @@ -70,10 +70,13 @@ int main(int argc, char *argv[]) { getBytes(NULL, additionalLength, false); } + unsigned long remainingBytes = state.fileSize; + //If file is encrypted, skip 12-byte encryption header if (state.isEncrypted) { getBytes(compressedChunk, ENCRYPTION_HEADER_LENGTH, false); decrypt(compressedChunk, ENCRYPTION_HEADER_LENGTH); + remainingBytes -= 12; } //Initialize xdelta3 @@ -87,14 +90,13 @@ int main(int argc, char *argv[]) { inflateInit(compressedChunk, uncompressedChunk, BUFFER_SIZE); //Read actual file - unsigned long remainingBytes = state.fileSize; bool needToRead = true; bool hasReachedEnd = false; unsigned long chunkSize; unsigned long uncompressedPosition = 0UL; while (remainingBytes > 0 || !hasReachedEnd) { - if (needToRead) { - chunkSize = min(BUFFER_SIZE - uncompressedPosition, remainingBytes); + if (needToRead && remainingBytes > 0) { + chunkSize = min(BUFFER_SIZE, remainingBytes); getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes); remainingBytes -= chunkSize;