Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e9fbcc9
Implement Tar APIs
carlossanlop Apr 13, 2022
0731cb2
Address some comment suggestions.
carlossanlop Apr 13, 2022
8f1f1af
Add SystemFormatsTarTestData package dependency entries and versions.
carlossanlop Apr 13, 2022
10df463
Merge the major and minor p/invokes into a single one.
carlossanlop Apr 14, 2022
da4af67
Address exception and nullability suggestions.
carlossanlop Apr 14, 2022
8710ceb
Adjust tests for the latest suggestions.
carlossanlop Apr 14, 2022
76e484c
Document elevation requirement to extract device files on Unix.
carlossanlop Apr 14, 2022
c9c4d85
Add tests to verify extraction without elevation throws for device fi…
carlossanlop Apr 14, 2022
e0dafda
Add separate expected mode for special files from assets (644).
carlossanlop Apr 14, 2022
5b8392b
Bump assets version to one with the fix
carlossanlop Apr 14, 2022
a16d4d9
Fix bugs and add tests for: timestamp conversion, extended attributes…
carlossanlop Apr 15, 2022
7ca674e
Validate entry.Name chars before extracting
carlossanlop Apr 15, 2022
560b789
Remove some minor todo comments
carlossanlop Apr 15, 2022
b3e5988
Add missing numeric value for PAL_S_IFCHR and its static assert
carlossanlop Apr 15, 2022
c22a8e7
Bug fixes:
carlossanlop Apr 16, 2022
d3e4f31
Bug fix: GNU can have two different metadata entries in a row if the …
carlossanlop Apr 16, 2022
23caa17
Add test to verify entry with subdir segments gets extracted by TarFi…
carlossanlop Apr 16, 2022
e0b0442
Rename UnknownFormat resource string to TarInvalidFormat, include for…
carlossanlop Apr 16, 2022
b682576
Bug fixes:
carlossanlop Apr 17, 2022
9fd01c3
Embed paths to exception message string when extracting file to diffe…
carlossanlop Apr 17, 2022
7b0d8c3
Bug fix: WriteEntry from file on Windows failing with V7 due to incom…
carlossanlop Apr 17, 2022
f1d9b7b
Bug fixes:
carlossanlop Apr 17, 2022
0980fbd
Use HAVE* in pal_io.c to detect library where makedev is available. D…
carlossanlop Apr 18, 2022
a28f3e5
Remove unnecessary TargetPlatformIdentifier override in src csproj.
carlossanlop Apr 18, 2022
7f2e516
Small refactor of VerifyOverwriteFileIsPossible
carlossanlop Apr 18, 2022
3f71b60
Remove parameter nullchecks.
carlossanlop Apr 18, 2022
cb855ed
Remove test method for attaching debugger.
carlossanlop Apr 18, 2022
dd40447
Remove devmajor and devminor duplicate todo message
carlossanlop Apr 18, 2022
9a28f12
Remove unused datetime method
carlossanlop Apr 19, 2022
40097c6
TMP exception with failed timestamp info
carlossanlop Apr 19, 2022
b1e8dfc
Remove failing device major/minor checks for now
carlossanlop Apr 19, 2022
c11e434
add FieldLocations static class, with position of first byte of each …
carlossanlop Apr 19, 2022
255ec96
Use InvariantCulture when converting the utf8 string to a double.
carlossanlop Apr 19, 2022
8ae7788
Copying file used by ExtractToDirectory test that throws, so it doesn…
carlossanlop Apr 19, 2022
d3cbdd2
Remove unused test method that opens and returns a filestream. We don…
carlossanlop Apr 19, 2022
6b5d078
Use a single rented buffer to read a whole header record. Convert rel…
carlossanlop Apr 19, 2022
19eb98d
Use ArrayPool for writing.
carlossanlop Apr 19, 2022
69ca3e7
Fix upper bound of DeviceMajor and DeviceMinor.
carlossanlop Apr 19, 2022
b1a2d5a
Remove async APIs from ref, comment them in src.
carlossanlop Apr 19, 2022
fb644dd
Add issue to TODO comments
carlossanlop Apr 19, 2022
cd40d62
Remove unused methods.
carlossanlop Apr 19, 2022
0ee2c33
Add InvariantCulture to double.ToString conversions.
carlossanlop Apr 19, 2022
58a3476
Fix test parsing a double, ensure it uses invariant culture.
carlossanlop Apr 20, 2022
fc0e568
More tests parsing a double, ensure invariant culture comparison.
carlossanlop Apr 20, 2022
5d81577
Verify link targets when extracting to directory. Disallow extracting…
carlossanlop Apr 20, 2022
a52dfe4
Avoid advancing stream anymore if end markers were found and GetNextE…
carlossanlop Apr 20, 2022
b227fa9
Add test that verifies stream is not advanced anymore after reading t…
carlossanlop Apr 20, 2022
5745b9f
Fix bug preventing correct generation of full path for extraction. Ad…
carlossanlop Apr 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bug fixes:
- When reading a regular file entry from one format, and writing it to an archive of another format, need to make sure the entry type is converted to the compatible type. Added tests to verify this for all formats.

Changes:
- Change NotSupportedException to InvalidOperationException. Adjusted tests.
- Improved resource messages based on suggestions.
- Clean unused interop code.
- Remove PNSE line in csproj.
  • Loading branch information
carlossanlop committed Apr 17, 2022
commit b682576ee53fec90fe5d8bc7f877c4bf4f676abf
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ internal static int CreateCharacterDevice(string pathName, uint mode, uint major
}

[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_MkNod", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)]
internal static partial int MkNod(string pathName, uint mode, uint major, uint minor);

[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_MakeDev", SetLastError = true)]
internal static partial ulong MakeDev(uint major, uint minor);
private static partial int MkNod(string pathName, uint mode, uint major, uint minor);

[LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDeviceIdentifiers", SetLastError = true)]
internal static partial void GetDeviceIdentifiers(ulong dev, out uint major, out uint minor);
Expand Down
23 changes: 7 additions & 16 deletions src/libraries/System.Formats.Tar/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -193,41 +193,32 @@
<value>A metadata entry of type '{0}' was unexpectedly found after a metadata entry of type '{1}'.</value>
</data>
<data name="TarEntriesInDifferentFormats" xml:space="preserve">
<value>The archive contains entries in different formats.</value>
<value>An entry in '{0}' format was found in an archive where other entries of format '{1}' have been found.</value>
</data>
<data name="TarEntryBlockOrCharacterExpected" xml:space="preserve">
<value>Cannot set the DevMajor or DevMinor fields on an entry that does not represent a block or character device.</value>
<value>Cannot set the 'DeviceMajor' or 'DeviceMinor' fields on an entry that does not represent a block or character device.</value>
</data>
<data name="TarEntryHardLinkOrSymLinkExpected" xml:space="preserve">
<value>Cannot set the LinkName field on an entry that does not represent a hard link or a symbolic link.</value>
</data>
<data name="TarEntryModeOutOfRange" xml:space="preserve">
<value>The mode must be a base 10 number between 0 and 511 (777 in octal).</value>
</data>
<data name="TarEntryNotARegularFile" xml:space="preserve">
<value>Entry type is not a regular file, so it does not support setting the data stream.</value>
<data name="TarEntryDoesNotSupportDataStream" xml:space="preserve">
<value>The entry '{0}' has a '{1}' type, which does not support setting a data stream.</value>
</data>
<data name="TarEntryTypeNotSupported" xml:space="preserve">
<value>Entry type '{0}' not supported in format '{1}'.</value>
</data>
<data name="TarEntryTypeNotSupportedForExtracting" xml:space="preserve">
<value>Entry type not supported for extraction: '{0}'</value>
<value>Entry type '{0}' not supported for extraction.</value>
</data>
<data name="TarExtractingResultsInOutside" xml:space="preserve">
<value>Extracting Tar entry would have resulted in a file outside the specified destination directory.</value>
</data>
<data name="TarGnuFormatExpected" xml:space="preserve">
<value>A GNU format was expected, but could not be reliably determined for entry '{0}'.</value>
<value>Entry '{0}' was expected to be in the GNU format, but did not have the expected version data.</value>
</data>
<data name="TarInvalidFormat" xml:space="preserve">
<value>The archive format is invalid: '{0}'</value>
</data>
<data name="TarMalformedTwoExtendedAttributesEntries" xml:space="preserve">
<value>The archive is malformed. It contains two extended attributes entries in a row.</value>
</data>
<data name="TarPaxFormatExpected" xml:space="preserve">
<value>A PAX format was expected, but could not be reliably determined for entry '{0}'.</value>
</data>
<data name="TarPosixFormatExpected" xml:space="preserve">
<value>A POSIX format was expected (Ustar or PAX), but could not be reliably determined for entry '{0}'.</value>
</data>
Expand All @@ -241,7 +232,7 @@
<value>The archive has more than one global extended attributes entry.</value>
</data>
<data name="TarUnsupportedFile" xml:space="preserve">
<value>The file '{0}' is not supported for tar archiving.</value>
<value>The file '{0}' is a type of file not supported for tar archiving.</value>
</data>
<data name="UnauthorizedAccess_IODenied_NoPathName" xml:space="preserve">
<value>Access to the path is denied.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == ''">SR.PlatformNotSupported_SystemFormatsTar</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Formats\Tar\FieldLengths.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal GnuTarEntry(TarHeader header, TarReader readerOfOrigin)
/// <param name="entryType">The type of the entry.</param>
/// <param name="entryName">A string with the relative path and file name of this entry.</param>
/// <exception cref="ArgumentException"><paramref name="entryName"/> is null or empty.</exception>
/// <exception cref="NotSupportedException">The entry type is not supported for creating an entry.</exception>
/// <exception cref="InvalidOperationException">The entry type is not supported for creating an entry.</exception>
/// <remarks>When creating an instance using the <see cref="GnuTarEntry(TarEntryType, string)"/> constructor, only the following entry types are supported:
/// <list type="bullet">
/// <item>In all platforms: <see cref="TarEntryType.Directory"/>, <see cref="TarEntryType.HardLink"/>, <see cref="TarEntryType.SymbolicLink"/>, <see cref="TarEntryType.RegularFile"/>.</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal PaxTarEntry(TarHeader header, TarReader readerOfOrigin)
/// <param name="entryType">The type of the entry.</param>
/// <param name="entryName">A string with the relative path and file name of this entry.</param>
/// <exception cref="ArgumentException"><paramref name="entryName"/> is null or empty.</exception>
/// <exception cref="NotSupportedException">The entry type is not supported for creating an entry.</exception>
/// <exception cref="InvalidOperationException">The entry type is not supported for creating an entry.</exception>
/// <remarks><para>When creating an instance using the <see cref="PaxTarEntry(TarEntryType, string)"/> constructor, only the following entry types are supported:</para>
/// <list type="bullet">
/// <item>In all platforms: <see cref="TarEntryType.Directory"/>, <see cref="TarEntryType.HardLink"/>, <see cref="TarEntryType.SymbolicLink"/>, <see cref="TarEntryType.RegularFile"/>.</item>
Expand Down Expand Up @@ -62,7 +62,7 @@ public PaxTarEntry(TarEntryType entryType, string entryName!!)
/// <param name="extendedAttributes">An enumeration of string key-value pairs that represents the metadata to include in the Extended Attributes entry that precedes the current entry.</param>
/// <exception cref="ArgumentNullException"><paramref name="extendedAttributes"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="entryName"/> is null or empty.</exception>
/// <exception cref="NotSupportedException">The entry type is not supported for creating an entry.</exception>
/// <exception cref="InvalidOperationException">The entry type is not supported for creating an entry.</exception>
/// <remarks>When creating an instance using the <see cref="PaxTarEntry(TarEntryType, string)"/> constructor, only the following entry types are supported:
/// <list type="bullet">
/// <item>In all platforms: <see cref="TarEntryType.Directory"/>, <see cref="TarEntryType.HardLink"/>, <see cref="TarEntryType.SymbolicLink"/>, <see cref="TarEntryType.RegularFile"/>.</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal PosixTarEntry(TarEntryType entryType, string entryName, TarFormat forma
/// When the current entry represents a character device or a block device, the major number identifies the driver associated with the device.
/// </summary>
/// <remarks>Character and block devices are Unix-specific entry types.</remarks>
/// <exception cref="NotSupportedException">The entry does not represent a block device or a character device.</exception>
/// <exception cref="InvalidOperationException">The entry does not represent a block device or a character device.</exception>
/// <exception cref="ArgumentOutOfRangeException">Cannot set a negative value.</exception>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is inconsistent with the check actually being performed. Same for DeviceMinor below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the upper limit is wrong.

The devmajor and devminor fields in the header have a length of 8 bytes, and are stored as octal integers in ASCII.

Note: the spec does not indicate that they are stored in octal, but if you use the gnu tar tool to store a block/char device and inspect the file with a hex editor, the numbers are stored in octal. Also, the tar tool puts a null char in the last byte, even though this is also not documented in the spec.

So we have 7 available bytes, which means the upper bound is 7,777,777 in octal, or 2,097,151 in decimal. I'll adjust this and fix the exception message too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.ibm.com/docs/en/zos/2.3.0?topic=scd-tar-manipulate-tar-archive-files-copy-back-up-file

The POSIX 1003.1 standard defines formats for tar and USTAR archives that limit the modification time to a maximum value of 77777777777 (octal). Modification times that are larger than the maximum value are not properly saved. Modification times beyond 03:14:07 UTC on January 19, 2038 but less than or equal to the maximum value, are not properly saved or restored on z/OS V2R2 and earlier systems. They also might not be properly saved or restored on non-z/OS systems. However, on systems later than z/OS V2R2, such values are properly saved and restored. Due to these restrictions, the pax utility with the pax interchange format is the preferred method for processing time values beyond 03:14:07 UTC on January 19, 2038.

public int DeviceMajor
{
Expand All @@ -35,7 +35,7 @@ public int DeviceMajor
{
if (_header._typeFlag is not TarEntryType.BlockDevice and not TarEntryType.CharacterDevice)
{
throw new NotSupportedException(SR.TarEntryBlockOrCharacterExpected);
throw new InvalidOperationException(SR.TarEntryBlockOrCharacterExpected);
}

if (value < 0 || value > 99_999_999)
Expand All @@ -50,7 +50,7 @@ public int DeviceMajor
/// When the current entry represents a character device or a block device, the minor number is used by the driver to distinguish individual devices it controls.
/// </summary>
/// <remarks>Character and block devices are Unix-specific entry types.</remarks>
/// <exception cref="NotSupportedException">The entry does not represent a block device or a character device.</exception>
/// <exception cref="InvalidOperationException">The entry does not represent a block device or a character device.</exception>
/// <exception cref="ArgumentOutOfRangeException">Cannot set a negative value.</exception>
public int DeviceMinor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subsequently, would it make sense for DeviceMajor/Minor to be combined into a single property? e.g. of type (int Major, int Minor), or even Version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss this in a separate issue to determine if we want to modify these public APIs into what you proposed.

{
Expand All @@ -59,7 +59,7 @@ public int DeviceMinor
{
if (_header._typeFlag is not TarEntryType.BlockDevice and not TarEntryType.CharacterDevice)
{
throw new NotSupportedException(SR.TarEntryBlockOrCharacterExpected);
throw new InvalidOperationException(SR.TarEntryBlockOrCharacterExpected);
}
if (value < 0 || value > 99_999_999)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SeekableSubReadStream(Stream superStream, long startPosition, long maxLen
{
if (!superStream.CanSeek)
{
throw new NotSupportedException(SR.IO_NotSupported_UnseekableStream);
throw new InvalidOperationException(SR.IO_NotSupported_UnseekableStream);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SubReadStream(Stream superStream, long startPosition, long maxLength)
{
if (!superStream.CanRead)
{
throw new NotSupportedException(SR.IO_NotSupported_UnreadableStream);
throw new InvalidOperationException(SR.IO_NotSupported_UnreadableStream);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what situations will this exception be thrown? Should this be an assert instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We shouldn't reach all the way here with an unreadable stream. We already checked that in the public APIs.

_startInSuperStream = startPosition;
_positionInSuperStream = startPosition;
Expand Down Expand Up @@ -54,7 +54,7 @@ public override long Position
set
{
ThrowIfDisposed();
throw new NotSupportedException(SR.IO_NotSupported_UnseekableStream);
throw new InvalidOperationException(SR.IO_NotSupported_UnseekableStream);
}
}

Expand Down Expand Up @@ -158,13 +158,13 @@ protected async ValueTask<int> ReadAsyncCore(Memory<byte> buffer, CancellationTo
return ret;
}

public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(SR.IO_NotSupported_UnseekableStream);
public override long Seek(long offset, SeekOrigin origin) => throw new InvalidOperationException(SR.IO_NotSupported_UnseekableStream);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the wrapped stream is seekable, why don't we want this one to be seekable as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should rename this class to UnseekableSubReadStream.

For seekable streams, we wrap the main stream with the other class, SeekableSubReadStream, which overrides Seek and allows performing such action.


public override void SetLength(long value) => throw new NotSupportedException(SR.IO_NotSupported_UnseekableStream);
public override void SetLength(long value) => throw new InvalidOperationException(SR.IO_NotSupported_UnseekableStream);

public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(SR.IO_NotSupported_UnwritableStream);
public override void Write(byte[] buffer, int offset, int count) => throw new InvalidOperationException(SR.IO_NotSupported_UnwritableStream);

public override void Flush() => throw new NotSupportedException(SR.IO_NotSupported_UnwritableStream);
public override void Flush() => throw new InvalidOperationException(SR.IO_NotSupported_UnwritableStream);
Copy link
Member

@stephentoub stephentoub Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a nop. Flush is allowed to be used on read-only streams as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know. Will fix that.


// Close the stream for reading. Note that this does NOT close the superStream (since
// the substream is just 'a chunk' of the super-stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public abstract partial class TarEntry
partial void ExtractAsBlockDevice(string destinationFileName)
{
Debug.Assert(EntryType is TarEntryType.BlockDevice or TarEntryType.CharacterDevice);
throw new NotSupportedException(SR.IO_DeviceFiles_NotSupported);
throw new InvalidOperationException(SR.IO_DeviceFiles_NotSupported);
}

// Throws on Windows. Character devices are not supported on this platform.
partial void ExtractAsCharacterDevice(string destinationFileName)
{
Debug.Assert(EntryType is TarEntryType.BlockDevice or TarEntryType.CharacterDevice);
throw new NotSupportedException(SR.IO_DeviceFiles_NotSupported);
throw new InvalidOperationException(SR.IO_DeviceFiles_NotSupported);
}

// Throws on Windows. Fifo files are not supported on this platform.
partial void ExtractAsFifo(string destinationFileName)
{
Debug.Assert(EntryType is TarEntryType.Fifo);
throw new NotSupportedException(SR.IO_FifoFiles_NotSupported);
throw new InvalidOperationException(SR.IO_FifoFiles_NotSupported);
}

// Windows specific implementation of the method that extracts the current entry as a hard link.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal TarEntry(TarEntryType entryType, string entryName, TarFormat format)
ArgumentException.ThrowIfNullOrEmpty(entryName);

// Throws if format is unknown or out of range
TarHelpers.VerifyEntryTypeIsSupported(entryType, format);
TarHelpers.VerifyEntryTypeIsSupported(entryType, format, forWriting: false);

_readerOfOrigin = null;

Expand Down Expand Up @@ -101,14 +101,15 @@ public DateTimeOffset ModificationTime
/// <summary>
/// When the <see cref="EntryType"/> indicates a <see cref="TarEntryType.SymbolicLink"/> or a <see cref="TarEntryType.HardLink"/>, this property returns the link target path of such link.
/// </summary>
/// <exception cref="InvalidOperationException">Cannot set the link name if the entry type is not <see cref="TarEntryType.HardLink"/> or <see cref="TarEntryType.SymbolicLink"/>.</exception>
public string LinkName
{
get => _header._linkName;
set
{
if (_header._typeFlag is not TarEntryType.HardLink and not TarEntryType.SymbolicLink)
{
throw new NotSupportedException(SR.TarEntryHardLinkOrSymLinkExpected);
throw new InvalidOperationException(SR.TarEntryHardLinkOrSymLinkExpected);
}
_header._linkName = value;
}
Expand Down Expand Up @@ -169,7 +170,7 @@ public int Uid
/// <para>A directory exists with the same name as <paramref name="destinationFileName"/>.</para>
/// <para>-or-</para>
/// <para>An I/O problem occurred.</para></exception>
/// <exception cref="NotSupportedException">Attempted to extract an unsupported entry type.</exception>
/// <exception cref="InvalidOperationException">Attempted to extract an unsupported entry type.</exception>
/// <exception cref="UnauthorizedAccessException">Operation not permitted due to insufficient permissions.</exception>
public void ExtractToFile(string destinationFileName, bool overwrite)
{
Expand Down Expand Up @@ -231,7 +232,7 @@ public void ExtractToFile(string destinationFileName, bool overwrite)
case TarEntryType.SparseFile:
case TarEntryType.TapeVolume:
default:
throw new NotSupportedException(string.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType));
throw new InvalidOperationException(string.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType));
}
}

Expand All @@ -252,7 +253,7 @@ public void ExtractToFile(string destinationFileName, bool overwrite)
/// <para>A directory exists with the same name as <paramref name="destinationFileName"/>.</para>
/// <para>-or-</para>
/// <para>An I/O problem occurred.</para></exception>
/// <exception cref="NotSupportedException">Attempted to extract an unsupported entry type.</exception>
/// <exception cref="InvalidOperationException">Attempted to extract an unsupported entry type.</exception>
/// <exception cref="UnauthorizedAccessException">Operation not permitted due to insufficient permissions.</exception>
public Task ExtractToFileAsync(string destinationFileName, bool overwrite, CancellationToken cancellationToken = default)
{
Expand All @@ -265,7 +266,7 @@ public Task ExtractToFileAsync(string destinationFileName, bool overwrite, Cance
/// <value><para>Gets a stream that represents the data section of this entry.</para>
/// <para>Sets a new stream that represents the data section, if it makes sense for the <see cref="EntryType"/> to contain data; if a stream already existed, the old stream gets disposed before substituting it with the new stream. Setting a <see langword="null"/> stream is allowed.</para></value>
/// <remarks>If you write data to this data stream, make sure to rewind it to the desired start position before writing this entry into an archive using <see cref="TarWriter.WriteEntry(TarEntry)"/> or <see cref="TarWriter.WriteEntryAsync(TarEntry, CancellationToken)"/>.</remarks>
/// <exception cref="NotSupportedException">Setting a data section is not supported because the <see cref="EntryType"/> is not <see cref="TarEntryType.RegularFile"/> (or <see cref="TarEntryType.V7RegularFile"/> for an archive of <see cref="TarFormat.V7"/> format).</exception>
/// <exception cref="InvalidOperationException">Setting a data section is not supported because the <see cref="EntryType"/> is not <see cref="TarEntryType.RegularFile"/> (or <see cref="TarEntryType.V7RegularFile"/> for an archive of <see cref="TarFormat.V7"/> format).</exception>
/// <exception cref="IOException"><para>Cannot set an unreadable stream.</para>
/// <para>-or-</para>
/// <para>An I/O problem occurred.</para></exception>
Expand All @@ -276,7 +277,7 @@ public Stream? DataStream
{
if (!IsDataStreamSetterSupported())
{
throw new NotSupportedException(SR.TarEntryNotARegularFile);
throw new InvalidOperationException(string.Format(SR.TarEntryDoesNotSupportDataStream, Name, EntryType));
}

if (value != null && !value.CanRead)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private void ReadExtendedAttributesBlock(Stream archiveStream)
// 4096 is a common max path length, and also the size field is 12 bytes long, which is under int.MaxValue.
if (_size > int.MaxValue)
{
throw new NotSupportedException(string.Format(SR.TarSizeFieldTooLargeForExtendedAttribute, _typeFlag.ToString()));
throw new InvalidOperationException(string.Format(SR.TarSizeFieldTooLargeForExtendedAttribute, _typeFlag.ToString()));
}

byte[] buffer = new byte[(int)_size];
Expand Down
Loading