1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Adds WOZ CRC checking.

This commit is contained in:
Thomas Harte 2018-05-23 22:22:17 -04:00
parent 853261364e
commit ca4bc92c33

View File

@ -9,6 +9,7 @@
#include "WOZ.hpp"
#include "../../Track/PCMTrack.hpp"
#include "../../../../NumberTheory/CRC.hpp"
using namespace Storage::Disk;
@ -21,8 +22,20 @@ WOZ::WOZ(const std::string &file_name) :
};
if(!file_.check_signature(signature, 8)) throw Error::InvalidFormat;
// TODO: check CRC32, instead of skipping it.
file_.seek(4, SEEK_CUR);
// Check the file's CRC32, instead of skipping it.
const uint32_t crc = file_.get32le();
CRC::CRC32 crc_generator;
while(true) {
uint8_t next = file_.get8();
if(file_.eof()) break;
crc_generator.add(next);
}
if(crc != crc_generator.get_value()) {
throw Error::InvalidFormat;
}
// Retreat to the first byte after the CRC.
file_.seek(12, SEEK_SET);
// Parse all chunks up front.
bool has_tmap = false;