From 30646ccb074a755b64bfb857d084fb0b0fa188c3 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 8 Apr 2020 23:35:55 +0200 Subject: [PATCH 1/2] Fix an Amiga decoder bug where truncated sectors would be considered valid (the Amiga checksum algorithm is weak and zero bytes don't contribute to the checksum). --- arch/amiga/decoder.cc | 2 ++ lib/reader.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/amiga/decoder.cc b/arch/amiga/decoder.cc index 8fbd03de..40a41a77 100644 --- a/arch/amiga/decoder.cc +++ b/arch/amiga/decoder.cc @@ -32,6 +32,8 @@ AbstractDecoder::RecordType AmigaDecoder::advanceToNextRecord() void AmigaDecoder::decodeSectorRecord() { const auto& rawbits = readRawBits(AMIGA_RECORD_SIZE*16); + if (rawbits < (AMIGA_RECORD_SIZE*16)) + return; const auto& rawbytes = toBytes(rawbits).slice(0, AMIGA_RECORD_SIZE*2); const auto& bytes = decodeFmMfm(rawbits).slice(0, AMIGA_RECORD_SIZE); diff --git a/lib/reader.cc b/lib/reader.cc index 59980270..e16a52d9 100644 --- a/lib/reader.cc +++ b/lib/reader.cc @@ -261,13 +261,13 @@ void readDiskCommand(AbstractDecoder& decoder) if (dumpSectors) { std::cout << "\nDecoded sectors follow:\n\n"; - for (auto& i : readSectors) + for (auto& sector : track->sectors) { - auto& sector = i.second; - std::cout << fmt::format("{}.{:02}.{:02}: I+{:.2f}us with {:.2f}us clock\n", - sector->logicalTrack, sector->logicalSide, sector->logicalSector, - sector->position.ns() / 1000.0, sector->clock / 1000.0); - hexdump(std::cout, sector->data); + std::cout << fmt::format("{}.{:02}.{:02}: I+{:.2f}us with {:.2f}us clock: status {}\n", + sector.logicalTrack, sector.logicalSide, sector.logicalSector, + sector.position.ns() / 1000.0, sector.clock / 1000.0, + sector.status); + hexdump(std::cout, sector.data); std::cout << std::endl; } } From 1fd65452c43aaf4558cbf3c8850cd2d23fd3995b Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 8 Apr 2020 23:37:08 +0200 Subject: [PATCH 2/2] Typo fix. --- arch/amiga/decoder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/amiga/decoder.cc b/arch/amiga/decoder.cc index 40a41a77..10e45cd1 100644 --- a/arch/amiga/decoder.cc +++ b/arch/amiga/decoder.cc @@ -32,7 +32,7 @@ AbstractDecoder::RecordType AmigaDecoder::advanceToNextRecord() void AmigaDecoder::decodeSectorRecord() { const auto& rawbits = readRawBits(AMIGA_RECORD_SIZE*16); - if (rawbits < (AMIGA_RECORD_SIZE*16)) + if (rawbits.size() < (AMIGA_RECORD_SIZE*16)) return; const auto& rawbytes = toBytes(rawbits).slice(0, AMIGA_RECORD_SIZE*2); const auto& bytes = decodeFmMfm(rawbits).slice(0, AMIGA_RECORD_SIZE);