Guard against null block descriptors in SCSI modes. Fixes #387.

This commit is contained in:
2020-11-01 22:00:52 +00:00
parent 080ad0ed51
commit 73faa18421
7 changed files with 52 additions and 72 deletions

View File

@@ -285,8 +285,7 @@ namespace Aaru.Core.Devices.Dumping
{
scsiMediumTypeTape = (byte)decMode.Value.Header.MediumType;
if(decMode.Value.Header.BlockDescriptors != null &&
decMode.Value.Header.BlockDescriptors.Length >= 1)
if(decMode.Value.Header.BlockDescriptors?.Length > 0)
scsiDensityCodeTape = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
blockSize = decMode.Value.Header.BlockDescriptors?[0].BlockLength ?? 0;
@@ -301,7 +300,7 @@ namespace Aaru.Core.Devices.Dumping
BlockLimits.BlockLimitsData? blockLimits = BlockLimits.Decode(cmdBuf);
if(blockLimits?.minBlockLen > blockSize)
blockSize = blockLimits.Value.minBlockLen;
blockSize = blockLimits?.minBlockLen ?? 0;
}
if(blockSize == 0)
@@ -774,15 +773,12 @@ namespace Aaru.Core.Devices.Dumping
currentTapeFile =
(_outputPlugin as IWritableTapeImage).Files.FirstOrDefault(f => f.LastBlock ==
(_outputPlugin as IWritableTapeImage
)?.Files.Max(g => g.LastBlock));
(_outputPlugin as IWritableTapeImage
)?.Files.Max(g => g.LastBlock));
currentTapePartition =
(_outputPlugin as IWritableTapeImage).TapePartitions.FirstOrDefault(p => p.LastBlock ==
(_outputPlugin as
IWritableTapeImage)?.
TapePartitions.
Max(g => g.LastBlock));
(_outputPlugin as IWritableTapeImage)?.TapePartitions.Max(g => g.LastBlock));
}
if(mode6Data != null)

View File

@@ -167,8 +167,7 @@ namespace Aaru.Core.Devices.Dumping
{
scsiMediumType = (byte)decMode.Value.Header.MediumType;
if(decMode.Value.Header.BlockDescriptors != null &&
decMode.Value.Header.BlockDescriptors.Length >= 1)
if(decMode.Value.Header.BlockDescriptors?.Length > 0)
scsiDensityCode = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
containsFloppyPage = decMode.Value.Pages?.Aggregate(containsFloppyPage,

View File

@@ -630,10 +630,10 @@ namespace Aaru.Core.Devices.Report
if(decMode != null)
{
mediaTest.MediumType = (byte)decMode.Value.Header.MediumType;
mediaTest.MediumType = (byte?)decMode?.Header.MediumType;
if(decMode?.Header.BlockDescriptors.Length > 0)
mediaTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
if(decMode?.Header.BlockDescriptors?.Length > 0)
mediaTest.Density = (byte?)decMode?.Header.BlockDescriptors?[0].Density;
}
if(mediaType.StartsWith("CD-", StringComparison.Ordinal) ||
@@ -1280,12 +1280,10 @@ namespace Aaru.Core.Devices.Report
if(mediaTest.CanReadCorrectedSubchannelWithC2 == false)
mediaTest.CanReadCorrectedSubchannelWithC2 = !_dev.ReadCd(out buffer, out senseBuffer, 11, 2714,
1, MmcSectorTypes.Cdda, false, false,
false, MmcHeaderCodes.None, true,
false,
MmcErrorField.C2PointersAndBlock,
MmcSubchannel.Rw, _dev.Timeout,
out _);
1, MmcSectorTypes.Cdda, false, false,
false, MmcHeaderCodes.None, true, false,
MmcErrorField.C2PointersAndBlock,
MmcSubchannel.Rw, _dev.Timeout, out _);
AaruConsole.DebugWriteLine("SCSI Report", "Sense = {0}",
!mediaTest.CanReadCorrectedSubchannelWithC2);
@@ -1389,12 +1387,10 @@ namespace Aaru.Core.Devices.Report
if(mediaTest.CanReadCorrectedSubchannelWithC2 == false)
mediaTest.CanReadCorrectedSubchannelWithC2 = !_dev.ReadCd(out buffer, out senseBuffer, 16, 2714,
1, MmcSectorTypes.AllTypes, false,
false, true,
MmcHeaderCodes.AllHeaders, true, true,
MmcErrorField.C2PointersAndBlock,
MmcSubchannel.Rw, _dev.Timeout,
out _);
1, MmcSectorTypes.AllTypes, false, false,
true, MmcHeaderCodes.AllHeaders, true,
true, MmcErrorField.C2PointersAndBlock,
MmcSubchannel.Rw, _dev.Timeout, out _);
AaruConsole.DebugWriteLine("SCSI Report", "Sense = {0}",
!mediaTest.CanReadCorrectedSubchannelWithC2);
@@ -1496,12 +1492,10 @@ namespace Aaru.Core.Devices.Report
if(mediaTest.CanReadCorrectedSubchannelWithC2 == false)
mediaTest.CanReadCorrectedSubchannelWithC2 = !_dev.ReadCd(out buffer, out senseBuffer, 16, 2440,
1, MmcSectorTypes.AllTypes, false,
false, false, MmcHeaderCodes.None,
true, false,
MmcErrorField.C2PointersAndBlock,
MmcSubchannel.Rw, _dev.Timeout,
out _);
1, MmcSectorTypes.AllTypes, false, false,
false, MmcHeaderCodes.None, true, false,
MmcErrorField.C2PointersAndBlock,
MmcSubchannel.Rw, _dev.Timeout, out _);
AaruConsole.DebugWriteLine("SCSI Report", "Sense = {0}",
!mediaTest.CanReadCorrectedSubchannelWithC2);
@@ -1825,12 +1819,12 @@ namespace Aaru.Core.Devices.Report
// Skip Lead-Out pre-gap
uint firstSessionLeadOutLba = (uint)((firstSessionLeadOutTrack.PMIN * 60 * 75) +
(firstSessionLeadOutTrack.PSEC * 75) +
(firstSessionLeadOutTrack.PSEC * 75) +
firstSessionLeadOutTrack.PFRAME + 150);
// Skip second session track pre-gap
uint secondSessionLeadInLba = (uint)(((secondSessionFirstTrack.PMIN * 60 * 75) +
(secondSessionFirstTrack.PSEC * 75) +
(secondSessionFirstTrack.PSEC * 75) +
secondSessionFirstTrack.PFRAME) - 300);
AaruConsole.WriteLine("Trying SCSI READ CD in first session Lead-Out...");
@@ -1845,23 +1839,21 @@ namespace Aaru.Core.Devices.Report
if(mediaTest.CanReadingIntersessionLeadOut == false)
{
mediaTest.CanReadingIntersessionLeadOut = !_dev.ReadCd(out buffer, out senseBuffer,
firstSessionLeadOutLba, 2368, 1,
MmcSectorTypes.AllTypes, false,
false, false,
MmcHeaderCodes.AllHeaders, true,
false, MmcErrorField.None,
MmcSubchannel.Q16, _dev.Timeout,
out _);
firstSessionLeadOutLba, 2368, 1,
MmcSectorTypes.AllTypes, false, false,
false, MmcHeaderCodes.AllHeaders, true,
false, MmcErrorField.None,
MmcSubchannel.Q16, _dev.Timeout, out _);
if(mediaTest.CanReadingIntersessionLeadOut == false)
mediaTest.CanReadingIntersessionLeadOut = !_dev.ReadCd(out buffer, out senseBuffer,
firstSessionLeadOutLba, 2352, 1,
MmcSectorTypes.AllTypes, false,
false, false,
MmcHeaderCodes.AllHeaders, true,
false, MmcErrorField.None,
MmcSubchannel.None, _dev.Timeout,
out _);
firstSessionLeadOutLba, 2352, 1,
MmcSectorTypes.AllTypes, false,
false, false,
MmcHeaderCodes.AllHeaders, true,
false, MmcErrorField.None,
MmcSubchannel.None, _dev.Timeout,
out _);
}
AaruConsole.DebugWriteLine("SCSI Report", "Sense = {0}",
@@ -1881,22 +1873,20 @@ namespace Aaru.Core.Devices.Report
if(mediaTest.CanReadingIntersessionLeadIn == false)
{
mediaTest.CanReadingIntersessionLeadIn = !_dev.ReadCd(out buffer, out senseBuffer,
secondSessionLeadInLba, 2368, 1,
MmcSectorTypes.AllTypes, false, false,
false, MmcHeaderCodes.AllHeaders,
true, false, MmcErrorField.None,
MmcSubchannel.Q16, _dev.Timeout,
out _);
secondSessionLeadInLba, 2368, 1,
MmcSectorTypes.AllTypes, false, false,
false, MmcHeaderCodes.AllHeaders, true,
false, MmcErrorField.None,
MmcSubchannel.Q16, _dev.Timeout, out _);
if(mediaTest.CanReadingIntersessionLeadIn == false)
mediaTest.CanReadingIntersessionLeadIn = !_dev.ReadCd(out buffer, out senseBuffer,
secondSessionLeadInLba, 2352, 1,
MmcSectorTypes.AllTypes, false,
false, false,
MmcHeaderCodes.AllHeaders, true,
false, MmcErrorField.None,
MmcSubchannel.None, _dev.Timeout,
out _);
secondSessionLeadInLba, 2352, 1,
MmcSectorTypes.AllTypes, false, false,
false, MmcHeaderCodes.AllHeaders,
true, false, MmcErrorField.None,
MmcSubchannel.None, _dev.Timeout,
out _);
}
AaruConsole.DebugWriteLine("SCSI Report", "Sense = {0}",

View File

@@ -170,9 +170,8 @@ namespace Aaru.Core.Devices.Report
{
seqTest.MediumType = (byte)decMode.Value.Header.MediumType;
if(decMode.Value.Header.BlockDescriptors != null &&
decMode.Value.Header.BlockDescriptors.Length > 0)
seqTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
if(decMode.Value.Header.BlockDescriptors?.Length > 0)
seqTest.Density = (byte)decMode.Value.Header.BlockDescriptors?[0].Density;
}
AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for current media...");

View File

@@ -425,8 +425,7 @@ namespace Aaru.Core.Devices.Report
{
mediaTest.MediumType = (byte)decMode.Value.Header.MediumType;
if(decMode.Value.Header.BlockDescriptors != null &&
decMode.Value.Header.BlockDescriptors.Length > 0)
if(decMode?.Header.BlockDescriptors?.Length > 0)
mediaTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
}
@@ -634,8 +633,7 @@ namespace Aaru.Core.Devices.Report
{
capabilities.MediumType = (byte)decMode.Value.Header.MediumType;
if(decMode.Value.Header.BlockDescriptors != null &&
decMode.Value.Header.BlockDescriptors.Length > 0)
if(decMode?.Header.BlockDescriptors?.Length > 0)
capabilities.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
}

View File

@@ -166,8 +166,7 @@ namespace Aaru.Core.Media.Info
{
scsiMediumType = (byte)DeviceInfo.ScsiMode.Value.Header.MediumType;
if(DeviceInfo.ScsiMode.Value.Header.BlockDescriptors != null &&
DeviceInfo.ScsiMode.Value.Header.BlockDescriptors.Length >= 1)
if(DeviceInfo.ScsiMode?.Header.BlockDescriptors?.Length > 0)
scsiDensityCode = (byte)DeviceInfo.ScsiMode.Value.Header.BlockDescriptors[0].Density;
if(DeviceInfo.ScsiMode.Value.Pages != null)

View File

@@ -930,8 +930,7 @@ namespace Aaru.DiscImages
{
mediumType = (byte)decMode.Value.Header.MediumType;
if(decMode.Value.Header.BlockDescriptors != null &&
decMode.Value.Header.BlockDescriptors.Length >= 1)
if(decMode?.Header.BlockDescriptors?.Length > 0)
densityCode = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
if(decMode.Value.Pages != null)