1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-11 15:49:38 +00:00

Avoid potential extending run-out-of-bounds.

This commit is contained in:
Thomas Harte 2024-12-03 09:18:05 -05:00
parent 9fa71231c4
commit 0371b0507a

View File

@ -19,19 +19,20 @@ using namespace Storage::Tape;
*/
ZXSpectrumTAP::ZXSpectrumTAP(const std::string &file_name) :
file_(file_name)
file_(file_name, FileHolder::FileMode::Read)
{
// Check for a continuous series of blocks through to
// exactly file end.
//
// To consider: could also check those blocks of type 0
// and type ff for valid checksums?
while(true) {
while(file_.tell() != file_.stats().st_size) {
const uint16_t block_length = file_.get16le();
if(file_.eof()) throw ErrorNotZXSpectrumTAP;
if(file_.eof() || file_.tell() + block_length >= file_.stats().st_size) {
throw ErrorNotZXSpectrumTAP;
}
file_.seek(block_length, SEEK_CUR);
if(file_.tell() == file_.stats().st_size) break;
}
virtual_reset();