mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
🐛Fix offset calculation when building long blocks on reads in DiscImageChef format
This commit is contained in:
@@ -137,6 +137,8 @@ namespace DiscImageChef.DiscImages
|
|||||||
uint currentCacheSize;
|
uint currentCacheSize;
|
||||||
/// <summary>Cache of DDT entries.</summary>
|
/// <summary>Cache of DDT entries.</summary>
|
||||||
Dictionary<ulong, ulong> ddtEntryCache;
|
Dictionary<ulong, ulong> ddtEntryCache;
|
||||||
|
MemoryStream decompressedStream;
|
||||||
|
bool deduplicate;
|
||||||
/// <summary>On-memory deduplication table indexed by checksum.</summary>
|
/// <summary>On-memory deduplication table indexed by checksum.</summary>
|
||||||
Dictionary<byte[], ulong> deduplicationTable;
|
Dictionary<byte[], ulong> deduplicationTable;
|
||||||
/// <summary><see cref="CUETools.Codecs.FLAKE" /> writer.</summary>
|
/// <summary><see cref="CUETools.Codecs.FLAKE" /> writer.</summary>
|
||||||
@@ -188,8 +190,6 @@ namespace DiscImageChef.DiscImages
|
|||||||
/// <summary>In-memory deduplication table</summary>
|
/// <summary>In-memory deduplication table</summary>
|
||||||
ulong[] userDataDdt;
|
ulong[] userDataDdt;
|
||||||
bool writingLong;
|
bool writingLong;
|
||||||
bool deduplicate;
|
|
||||||
MemoryStream decompressedStream;
|
|
||||||
|
|
||||||
public DiscImageChef()
|
public DiscImageChef()
|
||||||
{
|
{
|
||||||
@@ -762,7 +762,8 @@ namespace DiscImageChef.DiscImages
|
|||||||
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
imageStream.Read(structureBytes, 0, structureBytes.Length);
|
||||||
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(cicmBlock));
|
structurePointer = Marshal.AllocHGlobal(Marshal.SizeOf(cicmBlock));
|
||||||
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(cicmBlock));
|
Marshal.Copy(structureBytes, 0, structurePointer, Marshal.SizeOf(cicmBlock));
|
||||||
cicmBlock = (CicmMetadataBlock)Marshal.PtrToStructure(structurePointer, typeof(CicmMetadataBlock));
|
cicmBlock = (CicmMetadataBlock)Marshal.PtrToStructure(structurePointer,
|
||||||
|
typeof(CicmMetadataBlock));
|
||||||
Marshal.FreeHGlobal(structurePointer);
|
Marshal.FreeHGlobal(structurePointer);
|
||||||
if(cicmBlock.identifier != BlockType.CicmBlock) break;
|
if(cicmBlock.identifier != BlockType.CicmBlock) break;
|
||||||
|
|
||||||
@@ -1469,7 +1470,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
||||||
"Can't found track containing requested sector");
|
"Can't found track containing requested sector");
|
||||||
|
|
||||||
if(trk.TrackStartSector + sectorAddress + length > trk.TrackEndSector + 1)
|
if(sectorAddress + length > trk.TrackEndSector + 1)
|
||||||
throw new ArgumentOutOfRangeException(nameof(length),
|
throw new ArgumentOutOfRangeException(nameof(length),
|
||||||
$"Requested more sectors ({length + sectorAddress}) than present in track ({trk.TrackEndSector - trk.TrackStartSector + 1}), won't cross tracks");
|
$"Requested more sectors ({length + sectorAddress}) than present in track ({trk.TrackEndSector - trk.TrackStartSector + 1}), won't cross tracks");
|
||||||
|
|
||||||
@@ -1486,12 +1487,16 @@ namespace DiscImageChef.DiscImages
|
|||||||
data = ReadSectors(sectorAddress, length);
|
data = ReadSectors(sectorAddress, length);
|
||||||
for(uint i = 0; i < length; i++)
|
for(uint i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
Array.Copy(sectorPrefix, (int)((sectorAddress + i) * 16), sectors,
|
Array.Copy(sectorPrefix, (int)((sectorAddress + i) * 16), sectors, (int)(i * 2352),
|
||||||
(int)((sectorAddress + i) * 2352), 16);
|
16);
|
||||||
Array.Copy(data, (int)((sectorAddress + i) * 2048), sectors,
|
Array.Copy(data, (int)(i * 2048), sectors,
|
||||||
(int)((sectorAddress + i) * 2352) + 16, 2048);
|
(int)(i * 2352) + 16, 2048);
|
||||||
Array.Copy(sectorSuffix, (int)((sectorAddress + i) * 288), sectors,
|
Array.Copy(sectorSuffix,
|
||||||
(int)((sectorAddress + i) * 2352) + 2064, 288);
|
(int)((sectorAddress + i) * 288),
|
||||||
|
sectors,
|
||||||
|
(int)
|
||||||
|
(i *
|
||||||
|
2352) + 2064, 288);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sectors;
|
return sectors;
|
||||||
@@ -1505,10 +1510,10 @@ namespace DiscImageChef.DiscImages
|
|||||||
data = ReadSectors(sectorAddress, length);
|
data = ReadSectors(sectorAddress, length);
|
||||||
for(uint i = 0; i < length; i++)
|
for(uint i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
Array.Copy(sectorPrefix, (int)((sectorAddress + i) * 16), sectors,
|
Array.Copy(sectorPrefix, (int)((sectorAddress + i) * 16), sectors, (int)(i * 2352),
|
||||||
(int)((sectorAddress + i) * 2352), 16);
|
16);
|
||||||
Array.Copy(data, (int)((sectorAddress + i) * 2336), sectors,
|
Array.Copy(data, (int)(i * 2336), sectors,
|
||||||
(int)((sectorAddress + i) * 2352) + 16, 2336);
|
(int)(i * 2352) + 16, 2336);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sectors;
|
return sectors;
|
||||||
@@ -1550,9 +1555,9 @@ namespace DiscImageChef.DiscImages
|
|||||||
for(uint i = 0; i < length; i++)
|
for(uint i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
Array.Copy(sectorSubchannel, (int)((sectorAddress + i) * tagSize), sectors,
|
Array.Copy(sectorSubchannel, (int)((sectorAddress + i) * tagSize), sectors,
|
||||||
(int)((sectorAddress + i) * sectorSize + 512), tagSize);
|
(int)(i * sectorSize + 512), tagSize);
|
||||||
Array.Copy(data, (int)((sectorAddress + i) * 512), sectors,
|
Array.Copy(data, (int)((sectorAddress + i) * 512),
|
||||||
(int)((sectorAddress + i) * 512), 512);
|
sectors, (int)(i * 512), 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sectors;
|
return sectors;
|
||||||
@@ -1887,7 +1892,8 @@ namespace DiscImageChef.DiscImages
|
|||||||
("sha1", typeof(bool), "Calculate and store SHA1 of image's user data"),
|
("sha1", typeof(bool), "Calculate and store SHA1 of image's user data"),
|
||||||
("sha256", typeof(bool), "Calculate and store SHA256 of image's user data"),
|
("sha256", typeof(bool), "Calculate and store SHA256 of image's user data"),
|
||||||
("spamsum", typeof(bool), "Calculate and store SpamSum of image's user data"),
|
("spamsum", typeof(bool), "Calculate and store SpamSum of image's user data"),
|
||||||
("deduplicate", typeof(bool), "Store only unique sectors. This consumes more memory and is slower, but it's enabled by default")
|
("deduplicate", typeof(bool),
|
||||||
|
"Store only unique sectors. This consumes more memory and is slower, but it's enabled by default")
|
||||||
};
|
};
|
||||||
public IEnumerable<string> KnownExtensions => new[] {".dicf"};
|
public IEnumerable<string> KnownExtensions => new[] {".dicf"};
|
||||||
public bool IsWriting { get; private set; }
|
public bool IsWriting { get; private set; }
|
||||||
@@ -2626,8 +2632,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
byte[] hash = null;
|
byte[] hash = null;
|
||||||
|
|
||||||
// Compute hash only if asked to deduplicate, or the sector is empty (those will always be deduplicated)
|
// Compute hash only if asked to deduplicate, or the sector is empty (those will always be deduplicated)
|
||||||
if(deduplicate || ArrayHelpers.ArrayIsNullOrEmpty(data))
|
if(deduplicate || ArrayHelpers.ArrayIsNullOrEmpty(data)) hash = checksumProvider.ComputeHash(data);
|
||||||
hash = checksumProvider.ComputeHash(data);
|
|
||||||
|
|
||||||
if(hash != null && deduplicationTable.TryGetValue(hash, out ulong pointer))
|
if(hash != null && deduplicationTable.TryGetValue(hash, out ulong pointer))
|
||||||
{
|
{
|
||||||
@@ -2753,8 +2758,7 @@ namespace DiscImageChef.DiscImages
|
|||||||
}
|
}
|
||||||
|
|
||||||
ulong ddtEntry = (ulong)((imageStream.Position << shift) + currentBlockOffset);
|
ulong ddtEntry = (ulong)((imageStream.Position << shift) + currentBlockOffset);
|
||||||
if(hash != null)
|
if(hash != null) deduplicationTable.Add(hash, ddtEntry);
|
||||||
deduplicationTable.Add(hash, ddtEntry);
|
|
||||||
if(currentBlockHeader.compression == CompressionType.Flac)
|
if(currentBlockHeader.compression == CompressionType.Flac)
|
||||||
{
|
{
|
||||||
AudioBuffer audioBuffer = new AudioBuffer(AudioPCMConfig.RedBook, data, SAMPLES_PER_SECTOR);
|
AudioBuffer audioBuffer = new AudioBuffer(AudioPCMConfig.RedBook, data, SAMPLES_PER_SECTOR);
|
||||||
|
|||||||
Reference in New Issue
Block a user