Menu

#1406 7-Zip does not handle pre-DOS 4 disk images (FATHandler.cpp)

open
nobody
None
5
2014-08-21
2014-03-30
dosfan01
No

7-Zip does not handle pre-DOS 4 disk images. This issue is cause because of the following code in FatHandler.cpp function Parse:

UInt16 numRootDirEntries = Get16(p + 17);
if (numRootDirEntries == 0)
{
  if (codeOffset < 90)
    return false;
  NumFatBits = 32;
  NumRootDirSectors = 0;
}
else
{
  if (codeOffset < 62)
    return false;
   NumFatBits = 0;
   UInt32 mask = (1 << (SectorSizeLog - 5)) - 1;
   if ((numRootDirEntries & mask) != 0)
     return false;
   NumRootDirSectors = (numRootDirEntries + mask) >> (SectorSizeLog - 5);
 }

The if (codeOffset < 62) should be if (codeOffset < 36) because prior to DOS 4, the BIOS parameter block (BPB) in disk boot sectors only defined fields up to the number of hidden sectors field (20h-23h).

Patching v9.20 7z.dll (dated 11-18-2010) offset 10FDB byte from 3E to 24 fixes the problem.

Discussion

  • dosfan01

    dosfan01 - 2014-03-30

    Actually the field at 20h-23h is the 32-bit sector count, the hidden sector field is before that. Regardless 36 is the minimum code offset that should be used for FAT12/FAT16 disk images.

    DOS 3.2 boot sector (360K floppy):
    00000000  EB 34 90 49 42 4D 20 20 33 2E 32 00 02 02 01 00  .4.IBM  3.2.....
    00000010  02 70 00 D0 02 FD 02 00 09 00 02 00 00 00 00 00  .p..............
    00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0F  ................
    00000030  00 00 00 00 01 00 FA 33 C0 8E D0 BC 00 7C 16 07  .......3.....|..
    
    DOS 3.3 boot sector (720K floppy):
    00000000  EB 34 90 49 42 4D 20 20 33 2E 33 00 02 01 01 00  .4.IBM  3.3.....
    00000010  02 E0 00 A0 05 F9 05 00 09 00 02 00 00 00 00 00  ................
    00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12  ................
    00000030  00 00 00 00 01 00 FA 33 C0 8E D0 BC 00 7C 16 07  .......3.....|..
    
     

    Last edit: dosfan01 2014-03-30
  • Igor Pavlov

    Igor Pavlov - 2014-03-30

    Please give me the link to image example with smallest offset.

     
  • dosfan01

    dosfan01 - 2014-03-30

    Checking all versions of DOS from DOS 2.0 to DOS 7.0 the smallest offset I could find is used by Compaq MS-DOS 3.31 but you should use 36 as the minimum code offset as that is where the BPB ended prior to DOS 4. Note DOS 1.x did not have a BPB so those disks will always be unreadable by 7-Zip.

    Compaq MS-DOS 3.31 boot sector (on a 1.44MB floppy)

    00000000  EB 28 90 49 42 4D 20 20 33 2E 33 00 02 01 01 00  .(.IBM  3.3.....
    00000010  02 E0 00 40 0B F0 09 00 12 00 02 00 00 00 00 00  ...@............
    00000020  00 00 00 00 00 00 00 00 00 00 FA 33 ED B8 C0 07  ...........3....
    00000030  8E D8 C4 1E 1C 00 88 16 FD 01 0A D2 79 08 89 1E  ............y...
    00000040  24 00 8C 06 26 00 8E C5 8E D5 BC 00 7C FC 1E 36  $...&.......|..6
    00000050  C5 36 78 00 BF 2A 7C B9 0B 00 F3 A4 1F C6 06 2E  .6x..*|.........
    00000060  00 0F BF 78 00 B8 2A 7C AB 91 AB FB 8A 16 FD 01  ...x..*|........
    00000070  CD 13 A0 10 00 98 F7 26 16 00 03 06 0E 00 E8 73  .......&.......s
    00000080  00 E8 79 00 BB 00 05 53 E8 A0 00 5F BE 71 01 B9  ..y....S..._.q..
    00000090  0B 00 90 F3 A6 75 57 83 C7 15 B1 0B 90 90 F3 A6  .....uW.........
    000000A0  75 4C 26 8B 47 1C 99 8B 0E 0B 00 03 C1 48 F7 F1  uL&.G........H..
    000000B0  3D 14 00 7F 02 B0 14 96 A1 11 00 B1 04 D3 E8 E8  =...............
    000000C0  32 00 FF 36 24 00 C4 1E 6D 01 E8 30 00 E8 5B 00  2..6$...m..0..[.
    000000D0  2B F0 76 0D E8 1D 00 52 F7 26 0B 00 03 D8 5A EB  +.v....R.&....Z.
    000000E0  E9 5B 8A 2E 15 00 8A 16 FD 01 FF 2E 6D 01 BE 8B  .[..........m...
    000000F0  01 EB 54 90 01 06 24 00 11 2E 26 00 C3 A1 18 00  ..T...$...&.....
    00000100  F6 26 1A 00 91 A1 24 00 8B 16 26 00 F7 F1 92 8B  .&....$...&.....
    00000110  0E 18 00 F6 F1 2A CC 91 FE C5 86 E9 D0 CE D0 CE  .....*..........
    00000120  0A F1 86 F2 87 CA 8A 16 FD 01 C3 BF 05 00 B8 01  ................
    00000130  02 CD 13 72 03 B0 01 C3 80 FC 11 74 F8 33 C0 CD  ...r.......t.3..
    00000140  13 4F 75 EA BE D5 01 E8 1D 00 BE AB 01 E8 17 00  .Ou.............
    00000150  33 C0 CD 16 36 C7 06 72 04 34 12 EA 00 00 FF FF  3...6..r.4......
    00000160  B4 0E BB 07 00 CD 10 AC 3C 24 75 F4 C3 00 00 70  ........<$u....p
    00000170  00 49 4F 20 20 20 20 20 20 53 59 53 4D 53 44 4F  .IO      SYSMSDO
    00000180  53 20 20 20 53 59 53 00 00 00 00 0A 0D 4E 6F 6E  S   SYS......Non
    00000190  2D 53 79 73 74 65 6D 20 64 69 73 6B 20 6F 72 20  -System disk or
    000001A0  64 69 73 6B 20 65 72 72 6F 72 24 0A 0D 52 65 70  disk error$..Rep
    000001B0  6C 61 63 65 20 61 6E 64 20 73 74 72 69 6B 65 20  lace and strike
    000001C0  61 6E 79 20 6B 65 79 20 77 68 65 6E 20 72 65 61  any key when rea
    000001D0  64 79 0A 0D 24 0A 0D 44 69 73 6B 20 62 6F 6F 74  dy..$..Disk boot
    000001E0  20 66 61 69 6C 75 72 65 24 20 20 20 20 20 20 20   failure$
    000001F0  20 20 20 20 20 20 20 20 20 20 20 20 20 00 55 AA               .U.
    
     
  • dosfan01

    dosfan01 - 2014-03-30

    Found an ever smaller code offset with Multitasking MS-DOS 4.0 (360K floppy):

    00000000  EB 24 90 49 42 4D 20 20 34 2E 30 00 02 02 01 00  .$.IBM  4.0.....
    00000010  02 70 00 D0 02 FD 02 00 09 00 02 00 00 00 00 00  .p..............
    00000020  00 00 00 00 00 CB FA 0E 1F B8 00 08 8E C0 BE 00  ................
    00000030  7C 8B FE B9 00 01 FC F3 A5 91 0E 06 E8 E6 FF 17  |...............
    00000040  BC 00 FC BB 78 00 36 C5 37 1E 56 16 53 BF 30 7C  ....x.6.7.V.S.0|
    00000050  36 8C 47 02 36 89 3F B9 0B 00 F3 A4 0E 1F C6 45  6.G.6.?........E
    00000060  F9 0F FB CD 13 72 63 A0 10 7C 98 F7 26 16 7C 03  .....rc..|..&.|.
    00000070  06 1C 7C 03 06 0E 7C A3 2E 7C 91 B8 20 00 F7 26  ..|...|..|.. ..&
    00000080  11 7C 8B 1E 0B 7C 03 C3 48 F7 F3 03 C1 A3 26 7C  .|...|..H.....&|
    00000090  16 07 BB 00 05 A1 2E 7C E8 91 00 B0 01 E8 A6 00  .......|........
    000000A0  72 15 8B FB B9 0B 00 51 BE BE 7D F3 A6 75 08 8D  r......Q..}..u..
    000000B0  7F 20 59 F3 A6 74 18 BE 5F 7D E8 69 00 32 E4 CD  . Y..t.._}.i.2..
    000000C0  16 5E 1F 8F 04 8F 44 02 CD 19 BE A8 7D EB EB 26  .^....D.....}..&
    000000D0  A1 1C 05 33 D2 F7 36 0B 7C FE C0 A2 2B 7C A1 26  ...3..6.|...+|.&
    000000E0  7C A3 2C 7C BB 00 07 A1 26 7C E8 3F 00 A1 18 7C  |.,|....&|.?...|
    000000F0  2A 06 2A 7C 40 50 E8 4D 00 58 72 CE 28 06 2B 7C  *.*|@P.M.Xr.(.+|
    00000100  76 0C 01 06 26 7C F7 26 0B 7C 03 D8 EB D9 8A 2E  v...&|.&.|......
    00000110  15 7C 8A 16 1E 7C 8B 1E 2C 7C EA 00 00 70 00 B4  .|...|..,|...p..
    00000120  0E BB 07 00 CD 10 AC 0A C0 75 F4 C3 33 D2 F7 36  .........u..3..6
    00000130  18 7C FE C2 88 16 2A 7C 33 D2 F7 36 1A 7C 88 16  .|....*|3..6.|..
    00000140  1F 7C A3 28 7C C3 B4 02 8B 16 28 7C B1 06 D2 E6  .|.(|.....(|....
    00000150  0A 36 2A 7C 8B CA 86 E9 8B 16 1E 7C CD 13 C3 0D  .6*|.......|....
    00000160  0A 4E 6F 6E 2D 53 79 73 74 65 6D 20 64 69 73 6B  .Non-System disk
    00000170  20 6F 72 20 64 69 73 6B 20 65 72 72 6F 72 0D 0A   or disk error..
    00000180  52 65 70 6C 61 63 65 20 61 6E 64 20 73 74 72 69  Replace and stri
    00000190  6B 65 20 61 6E 79 20 6B 65 79 20 77 68 65 6E 20  ke any key when
    000001A0  72 65 61 64 79 0D 0A 00 0D 0A 44 69 73 6B 20 42  ready.....Disk B
    000001B0  6F 6F 74 20 66 61 69 6C 75 72 65 0D 0A 00 49 42  oot failure...IB
    000001C0  4D 42 49 4F 20 20 43 4F 4D 49 42 4D 44 4F 53 20  MBIO  COMIBMDOS
    000001D0  20 43 4F 4D 00 00 00 00 00 00 00 00 00 00 00 00   COM............
    000001E0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    000001F0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA  ..............U.
    

    Images here: http://jsmachines.net/disks/pc/dos/microsoft/4.0M/

     

    Last edit: dosfan01 2014-03-30
  • Igor Pavlov

    Igor Pavlov - 2014-03-31

    7-Zip 9.32 supports MS-DOS 2.0+ FAT images.

     

Log in to post a comment.