From d45231c1a8bcb5cb6e890945ac7c19d07ae867e7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 25 May 2018 18:40:15 -0400 Subject: [PATCH] Introduces an additional validation test. Thereby satisfying the TODO. --- Storage/Disk/DiskImage/Formats/NIB.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Storage/Disk/DiskImage/Formats/NIB.cpp b/Storage/Disk/DiskImage/Formats/NIB.cpp index 81049673f..830873435 100644 --- a/Storage/Disk/DiskImage/Formats/NIB.cpp +++ b/Storage/Disk/DiskImage/Formats/NIB.cpp @@ -30,7 +30,13 @@ NIB::NIB(const std::string &file_name) : throw Error::InvalidFormat; } - // TODO: all other validation. I.e. does this look like a GCR disk? + // A real NIB should have every single top bit set. Yes, 1/8th of the + // file size is a complete waste. But it provides a hook for validation. + while(true) { + uint8_t next = file_.get8(); + if(file_.eof()) break; + if(!(next & 0x80)) throw Error::InvalidFormat; + } } HeadPosition NIB::get_maximum_head_position() {