Prevent image-info to crash if TOC or PMA are empty.

This commit is contained in:
2018-06-23 20:38:54 +01:00
parent 3176377d3d
commit 0689a26e91

View File

@@ -207,19 +207,22 @@ namespace DiscImageChef.Core
{ {
byte[] toc = imageFormat.ReadDiskTag(MediaTagType.CD_FullTOC); byte[] toc = imageFormat.ReadDiskTag(MediaTagType.CD_FullTOC);
ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(toc, 0)); if(toc.Length > 0)
if(dataLen + 2 != toc.Length)
{ {
byte[] tmp = new byte[toc.Length + 2]; ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(toc, 0));
Array.Copy(toc, 0, tmp, 2, toc.Length); if(dataLen + 2 != toc.Length)
tmp[0] = (byte)((toc.Length & 0xFF00) >> 8); {
tmp[1] = (byte)(toc.Length & 0xFF); byte[] tmp = new byte[toc.Length + 2];
toc = tmp; Array.Copy(toc, 0, tmp, 2, toc.Length);
} tmp[0] = (byte)((toc.Length & 0xFF00) >> 8);
tmp[1] = (byte)(toc.Length & 0xFF);
toc = tmp;
}
DicConsole.WriteLine("CompactDisc Table of Contents contained in image:"); DicConsole.WriteLine("CompactDisc Table of Contents contained in image:");
DicConsole.Write("{0}", FullTOC.Prettify(toc)); DicConsole.Write("{0}", FullTOC.Prettify(toc));
DicConsole.WriteLine(); DicConsole.WriteLine();
}
} }
if(imageFormat.Info.ReadableMediaTags != null && if(imageFormat.Info.ReadableMediaTags != null &&
@@ -227,19 +230,22 @@ namespace DiscImageChef.Core
{ {
byte[] pma = imageFormat.ReadDiskTag(MediaTagType.CD_PMA); byte[] pma = imageFormat.ReadDiskTag(MediaTagType.CD_PMA);
ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(pma, 0)); if(pma.Length > 0)
if(dataLen + 2 != pma.Length)
{ {
byte[] tmp = new byte[pma.Length + 2]; ushort dataLen = Swapping.Swap(BitConverter.ToUInt16(pma, 0));
Array.Copy(pma, 0, tmp, 2, pma.Length); if(dataLen + 2 != pma.Length)
tmp[0] = (byte)((pma.Length & 0xFF00) >> 8); {
tmp[1] = (byte)(pma.Length & 0xFF); byte[] tmp = new byte[pma.Length + 2];
pma = tmp; Array.Copy(pma, 0, tmp, 2, pma.Length);
} tmp[0] = (byte)((pma.Length & 0xFF00) >> 8);
tmp[1] = (byte)(pma.Length & 0xFF);
pma = tmp;
}
DicConsole.WriteLine("CompactDisc Power Management Area contained in image:"); DicConsole.WriteLine("CompactDisc Power Management Area contained in image:");
DicConsole.Write("{0}", PMA.Prettify(pma)); DicConsole.Write("{0}", PMA.Prettify(pma));
DicConsole.WriteLine(); DicConsole.WriteLine();
}
} }
if(imageFormat.Info.ReadableMediaTags != null && if(imageFormat.Info.ReadableMediaTags != null &&