summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2016-03-29 12:13:23 +0100
committerJose Fonseca <jfonseca@vmware.com>2016-03-29 12:15:21 +0100
commit7c5a77c651bcde37005e6b6e209747edcc6c9361 (patch)
treec6117409c53dab251129815674a2694871711913 /cli
parentd2de4e3eab69585e346672a49c037e71b9382b45 (diff)
cli: Do CRC check of the compressed Brotli file.
Just in case.
Diffstat (limited to 'cli')
-rw-r--r--cli/cli_repack.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/cli/cli_repack.cpp b/cli/cli_repack.cpp
index e259661d..2e17cdeb 100644
--- a/cli/cli_repack.cpp
+++ b/cli/cli_repack.cpp
@@ -28,10 +28,12 @@
#include <getopt.h>
#include <iostream>
+#include <memory>
#include "cli.hpp"
#include <brotli/enc/encode.h>
+#include <zlib.h> // for crc32
#include "trace_file.hpp"
#include "trace_ostream.hpp"
@@ -80,9 +82,12 @@ private:
bool eof = false;
public:
+ uLong crc;
+
BrotliTraceIn(trace::File *s) :
stream(s)
{
+ crc = crc32(0L, Z_NULL, 0);
}
~BrotliTraceIn() {
@@ -101,6 +106,7 @@ public:
eof = true;
return nullptr;
}
+ crc32(crc, reinterpret_cast<const Bytef *>(buf), *bytes_read);
return buf;
}
};
@@ -158,6 +164,22 @@ repack_brotli(trace::File *inFile, const char *outFileName, int quality)
}
fclose(fout);
+ std::unique_ptr<trace::File> outFileIn(trace::File::createBrotli());
+ if (!outFileIn->open(outFileName)) {
+ std::cerr << "error: failed to open " << outFileName << " for reading\n";
+ return EXIT_FAILURE;
+ }
+ BrotliTraceIn outIn(outFileIn.get());
+ size_t bytes_read;
+ do {
+ outIn.Read(65536, &bytes_read);
+ } while (bytes_read > 0);
+
+ if (in.crc != outIn.crc) {
+ std::cerr << "error: CRC mismatch reading " << outFileName << "\n";
+ return EXIT_FAILURE;
+ }
+
return EXIT_SUCCESS;
}