🐛Correct trying to read past partition when El Torito boot image indicates to be bigger than it.

This commit is contained in:
2017-12-30 01:22:23 +00:00
parent ee8db1b290
commit df4a8a1ad5

View File

@@ -187,6 +187,7 @@ namespace DiscImageChef.Filesystems.ISO9660
pvd = (PrimaryVolumeDescriptor)Marshal.PtrToStructure(ptr, typeof(PrimaryVolumeDescriptor));
Marshal.FreeHGlobal(ptr);
}
break;
}
case 2:
@@ -200,7 +201,8 @@ namespace DiscImageChef.Filesystems.ISO9660
// Check if this is Joliet
if(svd.escape_sequences[0] == '%' && svd.escape_sequences[1] == '/')
if(svd.escape_sequences[2] == '@' || svd.escape_sequences[2] == 'C' ||
svd.escape_sequences[2] == 'E') jolietvd = svd;
svd.escape_sequences[2] == 'E')
jolietvd = svd;
else
DicConsole.WriteLine("ISO9660 plugin", "Found unknown supplementary volume descriptor");
@@ -223,8 +225,10 @@ namespace DiscImageChef.Filesystems.ISO9660
}
if(highSierra) decodedVd = DecodeVolumeDescriptor(hsvd.Value);
else if(cdi) decodedVd = DecodeVolumeDescriptor(fsvd.Value);
else decodedVd = DecodeVolumeDescriptor(pvd.Value);
else if(cdi)
decodedVd = DecodeVolumeDescriptor(fsvd.Value);
else
decodedVd = DecodeVolumeDescriptor(pvd.Value);
if(jolietvd != null) decodedJolietVd = DecodeJolietDescriptor(jolietvd.Value);
@@ -366,16 +370,21 @@ namespace DiscImageChef.Filesystems.ISO9660
break;
}
rrip |= nextSignature == RRIP_MAGIC || nextSignature == RRIP_POSIX_ATTRIBUTES ||
nextSignature == RRIP_POSIX_DEV_NO || nextSignature == RRIP_SYMLINK ||
nextSignature == RRIP_NAME || nextSignature == RRIP_CHILDLINK ||
nextSignature == RRIP_PARENTLINK || nextSignature == RRIP_RELOCATED_DIR ||
rrip |= nextSignature == RRIP_MAGIC ||
nextSignature == RRIP_POSIX_ATTRIBUTES ||
nextSignature == RRIP_POSIX_DEV_NO ||
nextSignature == RRIP_SYMLINK ||
nextSignature == RRIP_NAME ||
nextSignature == RRIP_CHILDLINK ||
nextSignature == RRIP_PARENTLINK ||
nextSignature == RRIP_RELOCATED_DIR ||
nextSignature == RRIP_TIMESTAMPS || nextSignature == RRIP_SPARSE;
ziso |= nextSignature == ZISO_MAGIC;
amiga |= nextSignature == AMIGA_MAGIC;
aaip |= nextSignature == AAIP_MAGIC || nextSignature == AAIP_MAGIC_OLD &&
sa[saOff + 3] == 1 && sa[saOff + 2] >= 9;
sa[saOff + 3] == 1 &&
sa[saOff + 2] >= 9;
saOff += sa[saOff + 2];
@@ -449,9 +458,12 @@ namespace DiscImageChef.Filesystems.ISO9660
foreach(byte[] erb in refareas)
{
ReferenceArea er = BigEndianMarshal.ByteArrayToStructureBigEndian<ReferenceArea>(erb);
string extId = Encoding.GetString(erb, Marshal.SizeOf(er), er.id_len);
string extDes = Encoding.GetString(erb, Marshal.SizeOf(er) + er.id_len, er.des_len);
string extSrc = Encoding.GetString(erb, Marshal.SizeOf(er) + er.id_len + er.des_len, er.src_len);
string extId =
Encoding.GetString(erb, Marshal.SizeOf(er), er.id_len);
string extDes =
Encoding.GetString(erb, Marshal.SizeOf(er) + er.id_len, er.des_len);
string extSrc =
Encoding.GetString(erb, Marshal.SizeOf(er) + er.id_len + er.des_len, er.src_len);
suspInformation.AppendFormat("Extension: {0}", counter).AppendLine();
suspInformation.AppendFormat("\tID: {0}, version {1}", extId, er.ext_ver).AppendLine();
suspInformation.AppendFormat("\tDescription: {0}", extDes).AppendLine();
@@ -467,8 +479,10 @@ namespace DiscImageChef.Filesystems.ISO9660
string fsFormat;
if(highSierra) fsFormat = "High Sierra Format";
else if(cdi) fsFormat = "CD-i";
else fsFormat = "ISO9660";
else if(cdi)
fsFormat = "CD-i";
else
fsFormat = "ISO9660";
isoMetadata.AppendFormat("{0} file system", fsFormat).AppendLine();
if(xaExtensions) isoMetadata.AppendLine("CD-ROM XA extensions present.");
@@ -486,16 +500,19 @@ namespace DiscImageChef.Filesystems.ISO9660
isoMetadata.AppendLine("This is a SegaCD / MegaCD disc.");
isoMetadata.AppendLine(CD.Prettify(segaCd));
}
if(saturn != null)
{
isoMetadata.AppendLine("This is a Sega Saturn disc.");
isoMetadata.AppendLine(Saturn.Prettify(saturn));
}
if(dreamcast != null)
{
isoMetadata.AppendLine("This is a Sega Dreamcast disc.");
isoMetadata.AppendLine(Dreamcast.Prettify(dreamcast));
}
isoMetadata.AppendFormat("{0}------------------------------", cdi ? "---------------" : "").AppendLine();
isoMetadata.AppendFormat("{0}VOLUME DESCRIPTOR INFORMATION:", cdi ? "FILE STRUCTURE " : "").AppendLine();
isoMetadata.AppendFormat("{0}------------------------------", cdi ? "---------------" : "").AppendLine();
@@ -503,7 +520,8 @@ namespace DiscImageChef.Filesystems.ISO9660
isoMetadata.AppendFormat("Volume identifier: {0}", decodedVd.VolumeIdentifier).AppendLine();
isoMetadata.AppendFormat("Volume set identifier: {0}", decodedVd.VolumeSetIdentifier).AppendLine();
isoMetadata.AppendFormat("Publisher identifier: {0}", decodedVd.PublisherIdentifier).AppendLine();
isoMetadata.AppendFormat("Data preparer identifier: {0}", decodedVd.DataPreparerIdentifier).AppendLine();
isoMetadata.AppendFormat("Data preparer identifier: {0}", decodedVd.DataPreparerIdentifier)
.AppendLine();
isoMetadata.AppendFormat("Application identifier: {0}", decodedVd.ApplicationIdentifier).AppendLine();
isoMetadata.AppendFormat("Volume creation date: {0}", decodedVd.CreationTime).AppendLine();
if(decodedVd.HasModificationTime)
@@ -527,7 +545,8 @@ namespace DiscImageChef.Filesystems.ISO9660
isoMetadata.AppendFormat("Volume identifier: {0}", decodedJolietVd.VolumeIdentifier).AppendLine();
isoMetadata.AppendFormat("Volume set identifier: {0}", decodedJolietVd.VolumeSetIdentifier)
.AppendLine();
isoMetadata.AppendFormat("Publisher identifier: {0}", decodedJolietVd.PublisherIdentifier).AppendLine();
isoMetadata.AppendFormat("Publisher identifier: {0}", decodedJolietVd.PublisherIdentifier)
.AppendLine();
isoMetadata.AppendFormat("Data preparer identifier: {0}", decodedJolietVd.DataPreparerIdentifier)
.AppendLine();
isoMetadata.AppendFormat("Application identifier: {0}", decodedJolietVd.ApplicationIdentifier)
@@ -573,8 +592,16 @@ namespace DiscImageChef.Filesystems.ISO9660
Marshal.FreeHGlobal(ptr);
initialEntry.boot_type = (ElToritoEmulation)((byte)initialEntry.boot_type & 0xF);
DicConsole.DebugWriteLine("DEBUG (ISO9660 plugin)", "initialEntry.load_rba = {0}",
initialEntry.load_rba);
DicConsole.DebugWriteLine("DEBUG (ISO9660 plugin)", "initialEntry.sector_count = {0}",
initialEntry.sector_count);
byte[] bootImage =
imagePlugin.ReadSectors(initialEntry.load_rba + partition.Start, initialEntry.sector_count);
initialEntry.load_rba + partition.Start + initialEntry.sector_count -
1 <= partition.End
? imagePlugin.ReadSectors(initialEntry.load_rba + partition.Start, initialEntry.sector_count)
: null;
isoMetadata.AppendLine("----------------------");
isoMetadata.AppendLine("EL TORITO INFORMATION:");
@@ -615,6 +642,7 @@ namespace DiscImageChef.Filesystems.ISO9660
}
isoMetadata.AppendFormat("\tSystem type: 0x{0:X2}", initialEntry.system_type).AppendLine();
if(bootImage != null)
isoMetadata.AppendFormat("\tBootable image's SHA1: {0}", sha1Ctx.Data(bootImage, out _))
.AppendLine();
}
@@ -624,7 +652,8 @@ namespace DiscImageChef.Filesystems.ISO9660
const int SECTION_COUNTER = 2;
while(toritoOff < vdSector.Length && (vdSector[toritoOff] == (byte)ElToritoIndicator.Header ||
while(toritoOff < vdSector.Length &&
(vdSector[toritoOff] == (byte)ElToritoIndicator.Header ||
vdSector[toritoOff] == (byte)ElToritoIndicator.LastHeader))
{
ptr = Marshal.AllocHGlobal(EL_TORITO_ENTRY_SIZE);
@@ -651,8 +680,13 @@ namespace DiscImageChef.Filesystems.ISO9660
isoMetadata.AppendFormat("\tEntry {0}:", entryCounter);
if(sectionEntry.bootable == ElToritoIndicator.Bootable)
{
bootImage = imagePlugin.ReadSectors(sectionEntry.load_rba + partition.Start,
sectionEntry.sector_count);
bootImage =
sectionEntry.load_rba + partition.Start +
sectionEntry.sector_count - 1 <= partition.End
? imagePlugin.ReadSectors(sectionEntry.load_rba + partition.Start,
sectionEntry.sector_count)
: null;
isoMetadata.AppendFormat("\t\tBootable on {0}", sectionHeader.platform_id).AppendLine();
isoMetadata.AppendFormat("\t\tBootable image starts at sector {0} and runs for {1} sectors",
sectionEntry.load_rba, sectionEntry.sector_count).AppendLine();
@@ -690,8 +724,9 @@ namespace DiscImageChef.Filesystems.ISO9660
sectionEntry.selection_criteria_type).AppendLine();
isoMetadata.AppendFormat("\t\tSystem type: 0x{0:X2}", sectionEntry.system_type)
.AppendLine();
isoMetadata.AppendFormat("\t\tBootable image's SHA1: {0}", sha1Ctx.Data(bootImage, out _))
.AppendLine();
if(bootImage != null)
isoMetadata.AppendFormat("\t\tBootable image's SHA1: {0}",
sha1Ctx.Data(bootImage, out _)).AppendLine();
}
else isoMetadata.AppendLine("\t\tNot bootable");
@@ -761,11 +796,13 @@ namespace DiscImageChef.Filesystems.ISO9660
XmlFsType.ModificationDate = decodedJolietVd.ModificationTime;
XmlFsType.ModificationDateSpecified = true;
}
if(decodedJolietVd.HasExpirationTime)
{
XmlFsType.ExpirationDate = decodedJolietVd.ExpirationTime;
XmlFsType.ExpirationDateSpecified = true;
}
if(decodedJolietVd.HasEffectiveTime)
{
XmlFsType.EffectiveDate = decodedJolietVd.EffectiveTime;
@@ -787,11 +824,13 @@ namespace DiscImageChef.Filesystems.ISO9660
XmlFsType.ModificationDate = decodedVd.ModificationTime;
XmlFsType.ModificationDateSpecified = true;
}
if(decodedVd.HasExpirationTime)
{
XmlFsType.ExpirationDate = decodedVd.ExpirationTime;
XmlFsType.ExpirationDateSpecified = true;
}
if(decodedVd.HasEffectiveTime)
{
XmlFsType.EffectiveDate = decodedVd.EffectiveTime;