Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
275c1e54
R
runtime
项目概览
dotNET Platform
/
runtime
12 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
275c1e54
编写于
8月 23, 2022
作者:
D
David Cantú
提交者:
GitHub
8月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SkipBlockAlignmentPadding must be executed for all entries (#74396)
上级
bd4bea62
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
142 addition
and
2 deletion
+142
-2
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs
...es/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs
+2
-2
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectory.Stream.Tests.cs
.../tests/TarFile/TarFile.ExtractToDirectory.Stream.Tests.cs
+32
-0
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectoryAsync.Stream.Tests.cs
...s/TarFile/TarFile.ExtractToDirectoryAsync.Stream.Tests.cs
+32
-0
src/libraries/System.Formats.Tar/tests/TarReader/TarReader.GetNextEntry.Tests.cs
...rmats.Tar/tests/TarReader/TarReader.GetNextEntry.Tests.cs
+38
-0
src/libraries/System.Formats.Tar/tests/TarReader/TarReader.GetNextEntryAsync.Tests.cs
....Tar/tests/TarReader/TarReader.GetNextEntryAsync.Tests.cs
+38
-0
未找到文件。
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs
浏览文件 @
275c1e54
...
@@ -225,10 +225,10 @@ internal void AdvanceDataStreamIfNeeded()
...
@@ -225,10 +225,10 @@ internal void AdvanceDataStreamIfNeeded()
{
{
long
bytesToSkip
=
_previouslyReadEntry
.
_header
.
_size
-
dataStream
.
Position
;
long
bytesToSkip
=
_previouslyReadEntry
.
_header
.
_size
-
dataStream
.
Position
;
TarHelpers
.
AdvanceStream
(
_archiveStream
,
bytesToSkip
);
TarHelpers
.
AdvanceStream
(
_archiveStream
,
bytesToSkip
);
TarHelpers
.
SkipBlockAlignmentPadding
(
_archiveStream
,
_previouslyReadEntry
.
_header
.
_size
);
dataStream
.
HasReachedEnd
=
true
;
// Now the pointer is beyond the limit, so any read attempts should throw
dataStream
.
HasReachedEnd
=
true
;
// Now the pointer is beyond the limit, so any read attempts should throw
}
}
}
}
TarHelpers
.
SkipBlockAlignmentPadding
(
_archiveStream
,
_previouslyReadEntry
.
_header
.
_size
);
}
}
}
}
...
@@ -267,10 +267,10 @@ internal async ValueTask AdvanceDataStreamIfNeededAsync(CancellationToken cancel
...
@@ -267,10 +267,10 @@ internal async ValueTask AdvanceDataStreamIfNeededAsync(CancellationToken cancel
{
{
long
bytesToSkip
=
_previouslyReadEntry
.
_header
.
_size
-
dataStream
.
Position
;
long
bytesToSkip
=
_previouslyReadEntry
.
_header
.
_size
-
dataStream
.
Position
;
await
TarHelpers
.
AdvanceStreamAsync
(
_archiveStream
,
bytesToSkip
,
cancellationToken
).
ConfigureAwait
(
false
);
await
TarHelpers
.
AdvanceStreamAsync
(
_archiveStream
,
bytesToSkip
,
cancellationToken
).
ConfigureAwait
(
false
);
await
TarHelpers
.
SkipBlockAlignmentPaddingAsync
(
_archiveStream
,
_previouslyReadEntry
.
_header
.
_size
,
cancellationToken
).
ConfigureAwait
(
false
);
dataStream
.
HasReachedEnd
=
true
;
// Now the pointer is beyond the limit, so any read attempts should throw
dataStream
.
HasReachedEnd
=
true
;
// Now the pointer is beyond the limit, so any read attempts should throw
}
}
}
}
await
TarHelpers
.
SkipBlockAlignmentPaddingAsync
(
_archiveStream
,
_previouslyReadEntry
.
_header
.
_size
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
}
}
...
...
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectory.Stream.Tests.cs
浏览文件 @
275c1e54
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.IO.Compression
;
using
System.Linq
;
using
System.Linq
;
using
Xunit
;
using
Xunit
;
...
@@ -145,5 +146,36 @@ private void Extract_LinkEntry_TargetInsideDirectory_Internal(TarEntryType entry
...
@@ -145,5 +146,36 @@ private void Extract_LinkEntry_TargetInsideDirectory_Internal(TarEntryType entry
Assert
.
Equal
(
2
,
Directory
.
GetFileSystemEntries
(
baseDir
).
Count
());
Assert
.
Equal
(
2
,
Directory
.
GetFileSystemEntries
(
baseDir
).
Count
());
}
}
[
Theory
]
[
InlineData
(
512
)]
[
InlineData
(
512
+
1
)]
[
InlineData
(
512
+
512
-
1
)]
public
void
Extract_UnseekableStream_BlockAlignmentPadding_DoesNotAffectNextEntries
(
int
contentSize
)
{
byte
[]
fileContents
=
new
byte
[
contentSize
];
Array
.
Fill
<
byte
>(
fileContents
,
0x1
);
using
var
archive
=
new
MemoryStream
();
using
(
var
compressor
=
new
GZipStream
(
archive
,
CompressionMode
.
Compress
,
leaveOpen
:
true
))
{
using
var
writer
=
new
TarWriter
(
compressor
);
var
entry1
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"file"
);
entry1
.
DataStream
=
new
MemoryStream
(
fileContents
);
writer
.
WriteEntry
(
entry1
);
var
entry2
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"next-file"
);
writer
.
WriteEntry
(
entry2
);
}
archive
.
Position
=
0
;
using
var
decompressor
=
new
GZipStream
(
archive
,
CompressionMode
.
Decompress
);
using
var
reader
=
new
TarReader
(
decompressor
);
using
TempDirectory
destination
=
new
TempDirectory
();
TarFile
.
ExtractToDirectory
(
decompressor
,
destination
.
Path
,
overwriteFiles
:
true
);
Assert
.
Equal
(
2
,
Directory
.
GetFileSystemEntries
(
destination
.
Path
,
"*"
,
SearchOption
.
AllDirectories
).
Count
());
}
}
}
}
}
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectoryAsync.Stream.Tests.cs
浏览文件 @
275c1e54
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.IO.Compression
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
@@ -174,5 +175,36 @@ await using (TarWriter writer = new TarWriter(archive, format, leaveOpen: true))
...
@@ -174,5 +175,36 @@ await using (TarWriter writer = new TarWriter(archive, format, leaveOpen: true))
}
}
}
}
}
}
[
Theory
]
[
InlineData
(
512
)]
[
InlineData
(
512
+
1
)]
[
InlineData
(
512
+
512
-
1
)]
public
async
Task
Extract_UnseekableStream_BlockAlignmentPadding_DoesNotAffectNextEntries_Async
(
int
contentSize
)
{
byte
[]
fileContents
=
new
byte
[
contentSize
];
Array
.
Fill
<
byte
>(
fileContents
,
0x1
);
using
var
archive
=
new
MemoryStream
();
using
(
var
compressor
=
new
GZipStream
(
archive
,
CompressionMode
.
Compress
,
leaveOpen
:
true
))
{
using
var
writer
=
new
TarWriter
(
compressor
);
var
entry1
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"file"
);
entry1
.
DataStream
=
new
MemoryStream
(
fileContents
);
await
writer
.
WriteEntryAsync
(
entry1
);
var
entry2
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"next-file"
);
await
writer
.
WriteEntryAsync
(
entry2
);
}
archive
.
Position
=
0
;
using
var
decompressor
=
new
GZipStream
(
archive
,
CompressionMode
.
Decompress
);
using
var
reader
=
new
TarReader
(
decompressor
);
using
TempDirectory
destination
=
new
TempDirectory
();
await
TarFile
.
ExtractToDirectoryAsync
(
decompressor
,
destination
.
Path
,
overwriteFiles
:
true
);
Assert
.
Equal
(
2
,
Directory
.
GetFileSystemEntries
(
destination
.
Path
,
"*"
,
SearchOption
.
AllDirectories
).
Count
());
}
}
}
}
}
src/libraries/System.Formats.Tar/tests/TarReader/TarReader.GetNextEntry.Tests.cs
浏览文件 @
275c1e54
...
@@ -250,5 +250,43 @@ public void GetNextEntry_UnseekableArchive_ReplaceDataStream_ExcludeFromDisposin
...
@@ -250,5 +250,43 @@ public void GetNextEntry_UnseekableArchive_ReplaceDataStream_ExcludeFromDisposin
Assert
.
Equal
(
"Substituted"
,
streamReader
.
ReadLine
());
Assert
.
Equal
(
"Substituted"
,
streamReader
.
ReadLine
());
}
}
}
}
[
Theory
]
[
InlineData
(
512
)]
[
InlineData
(
512
+
1
)]
[
InlineData
(
512
+
512
-
1
)]
public
void
BlockAlignmentPadding_DoesNotAffectNextEntries
(
int
contentSize
)
{
byte
[]
fileContents
=
new
byte
[
contentSize
];
Array
.
Fill
<
byte
>(
fileContents
,
0x1
);
using
var
archive
=
new
MemoryStream
();
using
(
var
writer
=
new
TarWriter
(
archive
,
leaveOpen
:
true
))
{
var
entry1
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"file"
);
entry1
.
DataStream
=
new
MemoryStream
(
fileContents
);
writer
.
WriteEntry
(
entry1
);
var
entry2
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"next-file"
);
writer
.
WriteEntry
(
entry2
);
}
archive
.
Position
=
0
;
using
var
unseekable
=
new
WrappedStream
(
archive
,
archive
.
CanRead
,
archive
.
CanWrite
,
canSeek
:
false
);
using
var
reader
=
new
TarReader
(
unseekable
);
TarEntry
e
=
reader
.
GetNextEntry
();
Assert
.
Equal
(
contentSize
,
e
.
Length
);
byte
[]
buffer
=
new
byte
[
contentSize
];
while
(
e
.
DataStream
.
Read
(
buffer
)
>
0
)
;
AssertExtensions
.
SequenceEqual
(
fileContents
,
buffer
);
e
=
reader
.
GetNextEntry
();
Assert
.
Equal
(
0
,
e
.
Length
);
e
=
reader
.
GetNextEntry
();
Assert
.
Null
(
e
);
}
}
}
}
}
src/libraries/System.Formats.Tar/tests/TarReader/TarReader.GetNextEntryAsync.Tests.cs
浏览文件 @
275c1e54
...
@@ -288,5 +288,43 @@ await using (WrappedStream wrapped = new WrappedStream(archive, canRead: true, c
...
@@ -288,5 +288,43 @@ await using (WrappedStream wrapped = new WrappedStream(archive, canRead: true, c
}
}
}
}
}
}
[
Theory
]
[
InlineData
(
512
)]
[
InlineData
(
512
+
1
)]
[
InlineData
(
512
+
512
-
1
)]
public
async
Task
BlockAlignmentPadding_DoesNotAffectNextEntries_Async
(
int
contentSize
)
{
byte
[]
fileContents
=
new
byte
[
contentSize
];
Array
.
Fill
<
byte
>(
fileContents
,
0x1
);
using
var
archive
=
new
MemoryStream
();
using
(
var
writer
=
new
TarWriter
(
archive
,
leaveOpen
:
true
))
{
var
entry1
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"file"
);
entry1
.
DataStream
=
new
MemoryStream
(
fileContents
);
await
writer
.
WriteEntryAsync
(
entry1
);
var
entry2
=
new
PaxTarEntry
(
TarEntryType
.
RegularFile
,
"next-file"
);
await
writer
.
WriteEntryAsync
(
entry2
);
}
archive
.
Position
=
0
;
using
var
unseekable
=
new
WrappedStream
(
archive
,
archive
.
CanRead
,
archive
.
CanWrite
,
canSeek
:
false
);
using
var
reader
=
new
TarReader
(
unseekable
);
TarEntry
e
=
await
reader
.
GetNextEntryAsync
();
Assert
.
Equal
(
contentSize
,
e
.
Length
);
byte
[]
buffer
=
new
byte
[
contentSize
];
while
(
e
.
DataStream
.
Read
(
buffer
)
>
0
)
;
AssertExtensions
.
SequenceEqual
(
fileContents
,
buffer
);
e
=
await
reader
.
GetNextEntryAsync
();
Assert
.
Equal
(
0
,
e
.
Length
);
e
=
await
reader
.
GetNextEntryAsync
();
Assert
.
Null
(
e
);
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录