Repository navigation
Closed
Labels
Description
Description
Currently i cannot use TarReader.GetNextEntryAsync whenever it sees a tar entry file with more than 8GB of size (my case is 9GB). In the entry header itself, instead of writing size of the file in octal, the size header is constructed like this:
[0x80, 0, 0, 0, <size in bytes big endian>]
Reproduction Steps
using TarReader tar = new TarReader(tarStream, true);
List<TarEntry> entries = new List<TarEntry>();
while (true)
{
TarEntry? entry = await tar.GetNextEntryAsync();
if (entry == null)
{
break;
}
entries.Add(entry);
}
...Expected behavior
Not error
Actual behavior
error:
Unable to parse number.
at System.Formats.Tar.TarHelpers.ThrowInvalidNumber()
at System.Formats.Tar.TarHelpers.ParseOctal[T](ReadOnlySpan`1 buffer)
at System.Formats.Tar.TarHeader.TryReadCommonAttributes(Span`1 buffer, TarEntryFormat initialFormat)
at System.Formats.Tar.TarHeader.TryReadAttributes(TarEntryFormat initialFormat, Span`1 buffer)
at System.Formats.Tar.TarHeader.<TryGetNextHeaderAsync>d__48.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Formats.Tar.TarReader.<TryGetNextEntryHeaderAsync>d__15.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Formats.Tar.TarReader.<GetNextEntryInternalAsync>d__13.MoveNext()
at System.Threading.Tasks.ValueTask`1.get_Result()
at xxxxx.<GetEntriesAsync>d__0.MoveNext() in [redacted]
Regression?
No response
Known Workarounds
this is currently my own tar parser implementation:
public async Task<TarEntry[]> GetEntriesAsync(Stream tarStream, CancellationToken cancellationToken)
{
byte[] entryHeaderBuff = new byte[512];
List<TarEntry> entries = new List<TarEntry>();
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
entryHeaderBuff[0] = 0; // Reset flag.
int read = await tarStream.ReadAsync(
entryHeaderBuff,
cancellationToken);
if (read < entryHeaderBuff.Length ||
entryHeaderBuff[0] == 0)
{
// No more entries.
break;
}
string fileName = Encoding.ASCII.GetString(entryHeaderBuff, 0, 100).Trim('\0');
long fileSize;
if (entryHeaderBuff[124] == 0x80)
{
byte[] sizeBuff = new byte[8];
entryHeaderBuff
.AsSpan()
.Slice(124 + 4, 8)
.CopyTo(sizeBuff);
Array.Reverse(sizeBuff);
fileSize = BitConverter.ToInt64(sizeBuff);
}
else
{
string sizeStr = Encoding.UTF8.GetString(entryHeaderBuff, 124, 12).Trim('\0');
fileSize = Convert.ToInt64(sizeStr, 8);
}
entries.Add(new TarEntry(fileName, fileSize));
// Next.
tarStream.Seek((fileSize + 511) / 512 * 512, SeekOrigin.Current);
}
return entries.ToArray();
}Configuration
No response
Other information
No response
Activity
ivanjx commentedon Dec 21, 2023
closing in favor of #93763