mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
parent
fce679c54f
commit
a29aa565a9
@ -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++;
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
namespace AssetRipper.IO.Files.Exceptions;
|
||||
|
||||
public sealed class InvalidFormatException : Exception
|
||||
{
|
||||
public InvalidFormatException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user