Guard several filesystems against crashes when identifying on a data buffer smaller than needed.

This commit is contained in:
2021-06-04 18:42:29 +01:00
parent 4eb8bb3a08
commit ce353d6884
4 changed files with 24 additions and 10 deletions

View File

@@ -82,14 +82,15 @@ namespace Aaru.Filesystems
byte sb_size_in_sectors;
if(imagePlugin.Info.SectorSize <= 0x400
) // Check if underlying device sector size is smaller than SuperBlock size
if(imagePlugin.Info.SectorSize <=
0x400) // Check if underlying device sector size is smaller than SuperBlock size
sb_size_in_sectors = (byte)(0x400 / imagePlugin.Info.SectorSize);
else
sb_size_in_sectors = 1; // If not a single sector can store it
if(partition.End <= partition.Start + (4 * (ulong)sb_size_in_sectors) + sb_size_in_sectors
) // Device must be bigger than SB location + SB size + offset
if(partition.End <=
partition.Start + (4 * (ulong)sb_size_in_sectors) +
sb_size_in_sectors) // Device must be bigger than SB location + SB size + offset
return false;
// Sectors in a cylinder
@@ -110,6 +111,9 @@ namespace Aaru.Filesystems
Select(i => imagePlugin.ReadSectors((ulong)i + partition.Start,
sb_size_in_sectors)))
{
if(sb_sector.Length < 0x400)
continue;
uint magic = BitConverter.ToUInt32(sb_sector, 0x3F8);
if(magic == XENIX_MAGIC ||
@@ -202,8 +206,8 @@ namespace Aaru.Filesystems
byte sb_size_in_sectors;
int offset = 0;
if(imagePlugin.Info.SectorSize <= 0x400
) // Check if underlying device sector size is smaller than SuperBlock size
if(imagePlugin.Info.SectorSize <=
0x400) // Check if underlying device sector size is smaller than SuperBlock size
sb_size_in_sectors = (byte)(0x400 / imagePlugin.Info.SectorSize);
else
sb_size_in_sectors = 1; // If not a single sector can store it