🐛 Don't read additional 12 bytes after each file

This commit is contained in:
C-3PO 2018-09-14 05:40:03 +02:00
parent f64412ebfe
commit 2299d8ed6e
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -70,10 +70,13 @@ int main(int argc, char *argv[]) {
getBytes(NULL, additionalLength, false); getBytes(NULL, additionalLength, false);
} }
unsigned long remainingBytes = state.fileSize;
//If file is encrypted, skip 12-byte encryption header //If file is encrypted, skip 12-byte encryption header
if (state.isEncrypted) { if (state.isEncrypted) {
getBytes(compressedChunk, ENCRYPTION_HEADER_LENGTH, false); getBytes(compressedChunk, ENCRYPTION_HEADER_LENGTH, false);
decrypt(compressedChunk, ENCRYPTION_HEADER_LENGTH); decrypt(compressedChunk, ENCRYPTION_HEADER_LENGTH);
remainingBytes -= 12;
} }
//Initialize xdelta3 //Initialize xdelta3
@ -87,14 +90,13 @@ int main(int argc, char *argv[]) {
inflateInit(compressedChunk, uncompressedChunk, BUFFER_SIZE); inflateInit(compressedChunk, uncompressedChunk, BUFFER_SIZE);
//Read actual file //Read actual file
unsigned long remainingBytes = state.fileSize;
bool needToRead = true; bool needToRead = true;
bool hasReachedEnd = false; bool hasReachedEnd = false;
unsigned long chunkSize; unsigned long chunkSize;
unsigned long uncompressedPosition = 0UL; unsigned long uncompressedPosition = 0UL;
while (remainingBytes > 0 || !hasReachedEnd) { while (remainingBytes > 0 || !hasReachedEnd) {
if (needToRead) { if (needToRead && remainingBytes > 0) {
chunkSize = min(BUFFER_SIZE - uncompressedPosition, remainingBytes); chunkSize = min(BUFFER_SIZE, remainingBytes);
getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes); getBytes(compressedChunk, chunkSize, chunkSize == remainingBytes);
remainingBytes -= chunkSize; remainingBytes -= chunkSize;