From aa655bdc6cde8b1850a0d36a05727e59054fce65 Mon Sep 17 00:00:00 2001 From: Irem Yuksel <113098562+iremyux@users.noreply.github.com> Date: Fri, 7 Nov 2025 14:16:42 +0100 Subject: [PATCH] Document extracting to a symbolic link and junction folder behavior for TarFile and ZipFile (#12026) * Add the information if you extract a zip/tar file to a pre existing junction folder, that link will be followed --- xml/System.Formats.Tar/TarFile.xml | 4 ++++ xml/System.IO.Compression/ZipFile.xml | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/xml/System.Formats.Tar/TarFile.xml b/xml/System.Formats.Tar/TarFile.xml index 7849eeac6ad..1eee19dd3c3 100644 --- a/xml/System.Formats.Tar/TarFile.xml +++ b/xml/System.Formats.Tar/TarFile.xml @@ -224,6 +224,7 @@ Extracts the contents of a stream that represents a tar archive into the specified directory. If a symbolic link or junction in the tar archive results in a file being extracted outside the specified , an is thrown to ensure extraction remains within the same directory. + If or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. Files of type , , or can only be extracted in Unix platforms. Elevation is required to extract a or to disk. @@ -275,6 +276,7 @@ Extracting one of the tar entries would have resulted in a file outside the spec Extracts the contents of a tar file into the specified directory. If a symbolic link or junction in the tar archive results in a file being extracted outside the specified , an is thrown to ensure extraction remains within the same directory. + If or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. Files of type , , or can only be extracted in Unix platforms. Elevation is required to extract a or to disk. @@ -325,6 +327,7 @@ Extracting one of the tar entries would have resulted in a file outside the spec A task that represents the asynchronous extraction operation. If a symbolic link or junction in the tar archive results in a file being extracted outside the specified , an is thrown to ensure extraction remains within the same directory. + If or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. Files of type , , or can only be extracted in Unix platforms. Elevation is required to extract a or to disk. This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as , are still thrown synchronously. For the stored exceptions, see the exceptions thrown by . @@ -380,6 +383,7 @@ Extracting one of the tar entries would have resulted in a file outside the spec A task that represents the asynchronous extraction operation. If a symbolic link or junction in the tar archive results in a file being extracted outside the specified , an is thrown to ensure extraction remains within the same directory. + If or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. Files of type , , or can only be extracted in Unix platforms. Elevation is required to extract a or to disk. This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as , are still thrown synchronously. For the stored exceptions, see the exceptions thrown by . diff --git a/xml/System.IO.Compression/ZipFile.xml b/xml/System.IO.Compression/ZipFile.xml index a6063c04b99..1c0436d90fe 100644 --- a/xml/System.IO.Compression/ZipFile.xml +++ b/xml/System.IO.Compression/ZipFile.xml @@ -1022,6 +1022,7 @@ An I/O error occurred while opening a file to be archived. Exceptions related to validating the paths in the or the files in the zip archive contained in parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by as its source entry has to the root of the archive. If an entry in the zip archive is a symbolic link, it's extracted as a regular folder since symbolic link information isn't preserved in the ZIP format. + If or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used. is , contains only white space, or contains at least one invalid character. @@ -1102,6 +1103,7 @@ An archive entry was compressed by using a compression method that isn't support This method creates the specified directory and all subdirectories. The destination directory cannot already exist. Exceptions related to validating the paths in the `destinationDirectoryName` or `sourceArchiveFileName` parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by `destinationDirectoryName` as its source entry has to the root of the archive. If an entry in the zip archive is a symbolic link, it's extracted as a regular folder since symbolic link information isn't preserved in the ZIP format. + If `destinationDirectoryName` or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. ## Examples This example shows how to create and extract a zip archive by using the class. It compresses the contents of a folder into a zip archive and extracts that content to a new folder. To use the class, you must reference the `System.IO.Compression.FileSystem` assembly in your project. @@ -1178,6 +1180,7 @@ An archive entry was compressed by using a compression method that isn't support Exceptions related to validating the paths in the or the files in the zip archive contained in parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by as its source entry has to the root of the archive. If an entry in the zip archive is a symbolic link, it's extracted as a regular folder since symbolic link information isn't preserved in the ZIP format. + If or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used. is , contains only white space, or contains at least one invalid character. @@ -1335,6 +1338,7 @@ Each entry will be extracted such that the extracted file has the same relative The `sourceArchiveFileName` and `destinationDirectoryName` parameters accept both relative and absolute paths. A relative path is interpreted as relative to the current working directory. If an entry in the zip archive is a symbolic link, it's extracted as a regular folder since symbolic link information isn't preserved in the ZIP format. +If `destinationDirectoryName` or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used. @@ -1443,6 +1447,7 @@ A has been compressed usi This method creates the specified directory and all subdirectories, if necessary. Exceptions related to validating the paths in the `destinationDirectoryName` or `sourceArchiveFileName` parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by `destinationDirectoryName` as its source entry has to the root of the archive. If an entry in the zip archive is a symbolic link, it's extracted as a regular folder since symbolic link information isn't preserved in the ZIP format. +If `destinationDirectoryName` or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. If `entryNameEncoding` is set to a value other than `null`, entry names and comments are decoded according to the following rules: @@ -1535,6 +1540,7 @@ If `entryNameEncoding` is set to `null`, entry names and comments are decoded ac Exceptions related to validating the paths in the or the files in the zip archive contained in parameters are thrown before extraction. Otherwise, if an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by as its source entry has to the root of the archive. If an entry in the zip archive is a symbolic link, it's extracted as a regular folder since symbolic link information isn't preserved in the ZIP format. + If or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used. is , contains only white space, or contains at least one invalid character. @@ -1632,6 +1638,7 @@ An archive entry was compressed by using a compression method that isn't support The `sourceArchiveFileName` and `destinationDirectoryName` parameters accept both relative and absolute paths. A relative path is interpreted as relative to the current working directory. If an entry in the zip archive is a symbolic link, it's extracted as a regular folder since symbolic link information isn't preserved in the ZIP format. + If `destinationDirectoryName` or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder. If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.