Reenable RandomAccessStream

Related: #1954
This commit is contained in:
ds5678 2025-10-12 21:29:58 -07:00
parent fce679c54f
commit a29aa565a9
3 changed files with 22 additions and 2 deletions

View File

@ -33,7 +33,11 @@ internal sealed class BundleFileBlockReader : IDisposable
// Avoid storing entire non-compresed entries in memory by mapping a stream to the block location.
if (m_blocksInfo.StorageBlocks.Length == 1 && m_blocksInfo.StorageBlocks[0].CompressionType == CompressionType.None)
{
//return m_stream.CreatePartial(m_dataOffset + entry.Offset, entry.Size);
if (m_dataOffset + entry.Offset + entry.Size > m_stream.Length)
{
throw new InvalidFormatException("Entry extends beyond the end of the stream.");
}
return m_stream.CreatePartial(m_dataOffset + entry.Offset, entry.Size);
}
// find block offsets
@ -133,6 +137,10 @@ internal sealed class BundleFileBlockReader : IDisposable
entryOffsetInsideBlock = 0;
long size = Math.Min(blockSize, left);
if (blockStream.Position + size > blockStream.Length)
{
throw new InvalidFormatException("Block extends beyond the end of the stream.");
}
using PartialStream partialStream = new(blockStream, blockStream.Position, size);
partialStream.CopyTo(entryStream);
blockIndex++;

View File

@ -0,0 +1,8 @@
namespace AssetRipper.IO.Files.Exceptions;
public sealed class InvalidFormatException : Exception
{
public InvalidFormatException(string message) : base(message)
{
}
}

View File

@ -9,6 +9,10 @@ public sealed class PartialStream : Stream
public PartialStream(Stream baseStream, long offset, long length, bool leaveOpen)
{
if (offset + length > baseStream.Length)
{
throw new ArgumentException("The base stream is not long enough for the given offset and length.");
}
m_stream = baseStream ?? throw new ArgumentNullException(nameof(baseStream));
m_baseOffset = offset;
Length = length;
@ -89,7 +93,7 @@ public sealed class PartialStream : Stream
}
else
{
m_stream.Dispose();
m_stream?.Dispose();
}
base.Dispose(disposing);
}