From 0c8f92a862c3d443f127d4020629b201d0a8cf3e Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Fri, 27 Jan 2017 10:59:47 +1100 Subject: [PATCH] sparse file bug --- .../diskbrowser/applefile/SHRPictureFile.java | 2 ++ .../diskbrowser/prodos/FileEntry.java | 23 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java index 348382d..05150f0 100644 --- a/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java +++ b/src/com/bytezone/diskbrowser/applefile/SHRPictureFile.java @@ -22,6 +22,8 @@ public class SHRPictureFile extends HiResImage while (ptr < buffer.length) { int len = HexFormatter.unsignedLong (buffer, ptr); + if (len == 0) + break; // int nameLen = buffer[ptr + 4] & 0xFF; String kind = HexFormatter.getPascalString (buffer, ptr + 4); byte[] data = new byte[Math.min (len, buffer.length - ptr)]; diff --git a/src/com/bytezone/diskbrowser/prodos/FileEntry.java b/src/com/bytezone/diskbrowser/prodos/FileEntry.java index 7faadee..206faef 100755 --- a/src/com/bytezone/diskbrowser/prodos/FileEntry.java +++ b/src/com/bytezone/diskbrowser/prodos/FileEntry.java @@ -172,6 +172,9 @@ class FileEntry extends CatalogEntry implements ProdosConstants parentDisk.setSectorType (keyBlock, parentDisk.indexSector); indexBlocks.add (disk.getDiskAddress (keyBlock)); byte[] buffer = disk.readSector (keyBlock); + + int maxBlocks = (endOfFile - 1) / 512 + 1; + for (int i = 0; i < 256; i++) { int block = HexFormatter.intValue (buffer[i], buffer[i + 256]); @@ -181,12 +184,13 @@ class FileEntry extends CatalogEntry implements ProdosConstants invalid = true; break; } - // System.out.printf ("%4d %02X %02X%n", block, fileType, auxType); - // should we break if block == 0 and it's not a text file? - // if (block == 0 && !(fileType == ProdosConstants.FILE_TYPE_TEXT && auxType > 0)) - // if (block == 0 && fileType != 4) - // break; - if (block != 0) + + if (dataBlocks.size () == maxBlocks) + break; + + if (block == 0) + dataBlocks.add (null); // allow for sparse image files + else { parentDisk.setSectorType (block, parentDisk.dataSector); dataBlocks.add (disk.getDiskAddress (block)); @@ -232,11 +236,13 @@ class FileEntry extends CatalogEntry implements ProdosConstants { if (file != null) return file; + if (invalid) { file = new DefaultAppleFile (name, null); return file; } + /* * Text files with reclen > 0 are random access, possibly with gaps between * records, so they need to be handled separately. @@ -432,6 +438,7 @@ class FileEntry extends CatalogEntry implements ProdosConstants } if (buffers.size () == 1 && name.endsWith (".S")) return new MerlinSource (name, buffers.get (0).buffer, auxType, endOfFile); + return new TextFile (name, buffers, auxType, endOfFile); } @@ -440,8 +447,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants List buffers = new ArrayList (); List addresses = new ArrayList (); readIndexBlock (keyPtr, addresses, buffers, 0); + if (buffers.size () == 1 && name.endsWith (".S")) return new MerlinSource (name, buffers.get (0).buffer, auxType, endOfFile); + return new TextFile (name, buffers, auxType, endOfFile); } @@ -454,8 +463,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants System.arraycopy (buffer, 0, exactBuffer, 0, endOfFile); buffer = exactBuffer; } + if (name.endsWith (".S")) return new MerlinSource (name, buffer, auxType, endOfFile); + return new TextFile (name, buffer, auxType, endOfFile); }