Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
b77565a8
R
runtime
项目概览
dotNET Platform
/
runtime
9 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
b77565a8
编写于
3月 14, 2023
作者:
S
Sean Reeser
浏览文件
操作
浏览文件
下载
差异文件
Merge commit '
0a396aca
' into internal-merge-7.0-2023-03-14-1018
上级
56da0d3f
0a396aca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
2 deletion
+57
-2
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
...braries/System.Private.CoreLib/src/Resources/Strings.resx
+6
-0
src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.NonAndroid.cs
...rivate.CoreLib/src/System/TimeZoneInfo.Unix.NonAndroid.cs
+46
-2
src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
...ibraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
+5
-0
未找到文件。
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
浏览文件 @
b77565a8
...
...
@@ -2603,6 +2603,9 @@
<data
name=
"InvalidProgram_Default"
xml:space=
"preserve"
>
<value>
Common Language Runtime detected an invalid program.
</value>
</data>
<data
name=
"InvalidTimeZone_InvalidId"
xml:space=
"preserve"
>
<value>
The time zone ID '{0}' is invalid.
</value>
</data>
<data
name=
"InvalidTimeZone_InvalidFileData"
xml:space=
"preserve"
>
<value>
The time zone ID '{0}' was found on the local computer, but the file at '{1}' was corrupt.
</value>
</data>
...
...
@@ -2627,6 +2630,9 @@
<data
name=
"IO_NoFileTableInInMemoryAssemblies"
xml:space=
"preserve"
>
<value>
This assembly does not have a file table because it was loaded from memory.
</value>
</data>
<data
name=
"IO_UnseekableFile"
xml:space=
"preserve"
>
<value>
Unsupported unseekable file.
</value>
</data>
<data
name=
"IO_EOF_ReadBeyondEOF"
xml:space=
"preserve"
>
<value>
Unable to read beyond the end of the stream.
</value>
</data>
...
...
src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.NonAndroid.cs
浏览文件 @
b77565a8
...
...
@@ -24,17 +24,61 @@ private static TimeZoneInfo GetLocalTimeZoneCore()
return
GetLocalTimeZoneFromTzFile
();
}
private
static
byte
[]
ReadAllBytesFromSeekableNonZeroSizeFile
(
string
path
,
int
maxFileSize
)
{
using
FileStream
fs
=
File
.
OpenRead
(
path
);
if
(!
fs
.
CanSeek
)
{
throw
new
IOException
(
SR
.
IO_UnseekableFile
);
}
if
(
fs
.
Length
==
0
||
fs
.
Length
>
maxFileSize
)
{
throw
new
IOException
(
fs
.
Length
==
0
?
SR
.
IO_InvalidReadLength
:
SR
.
IO_FileTooLong
);
}
byte
[]
bytes
=
new
byte
[
fs
.
Length
];
fs
.
ReadExactly
(
bytes
,
0
,
bytes
.
Length
);
return
bytes
;
}
// Bitmap covering the ASCII range. The bits is set for the characters [a-z], [A-Z], [0-9], '/', '-', and '_'.
private
static
byte
[]
asciiBitmap
=
new
byte
[]
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0xA8
,
0xFF
,
0x03
,
0xFE
,
0xFF
,
0xFF
,
0x87
,
0xFE
,
0xFF
,
0xFF
,
0x07
};
private
static
bool
IdContainsAnyDisallowedChars
(
string
zoneId
)
{
for
(
int
i
=
0
;
i
<
zoneId
.
Length
;
i
++)
{
int
c
=
zoneId
[
i
];
if
(
c
>
0x7F
)
{
return
true
;
}
int
value
=
c
>>
3
;
if
((
asciiBitmap
[
value
]
&
(
ulong
)(
1U
L
<<
(
c
-
(
value
<<
3
))))
==
0
)
{
return
true
;
}
}
return
false
;
}
private
static
TimeZoneInfoResult
TryGetTimeZoneFromLocalMachineCore
(
string
id
,
out
TimeZoneInfo
?
value
,
out
Exception
?
e
)
{
value
=
null
;
e
=
null
;
if
(
Path
.
IsPathRooted
(
id
)
||
IdContainsAnyDisallowedChars
(
id
))
{
e
=
new
TimeZoneNotFoundException
(
SR
.
Format
(
SR
.
InvalidTimeZone_InvalidId
,
id
));
return
TimeZoneInfoResult
.
TimeZoneNotFoundException
;
}
string
timeZoneDirectory
=
GetTimeZoneDirectory
();
string
timeZoneFilePath
=
Path
.
Combine
(
timeZoneDirectory
,
id
);
byte
[]
rawData
;
try
{
rawData
=
File
.
ReadAllBytes
(
timeZoneFilePath
);
rawData
=
ReadAllBytesFromSeekableNonZeroSizeFile
(
timeZoneFilePath
,
maxFileSize
:
20
*
1024
*
1024
/* 20 MB */
);
// timezone files usually less than 1 MB.
}
catch
(
UnauthorizedAccessException
ex
)
{
...
...
@@ -51,7 +95,7 @@ private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachineCore(string id,
e
=
ex
;
return
TimeZoneInfoResult
.
TimeZoneNotFoundException
;
}
catch
(
IOException
ex
)
catch
(
Exception
ex
)
when
(
ex
is
IOException
||
ex
is
OutOfMemoryException
)
{
e
=
new
InvalidTimeZoneException
(
SR
.
Format
(
SR
.
InvalidTimeZone_InvalidFileData
,
id
,
timeZoneFilePath
),
ex
);
return
TimeZoneInfoResult
.
InvalidTimeZoneException
;
...
...
src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
浏览文件 @
b77565a8
...
...
@@ -2083,6 +2083,11 @@ public static IEnumerable<object[]> ConvertTime_DateTimeOffset_InvalidDestinatio
yield
return
new
object
[]
{
s_strPacific
+
"\\Display"
};
yield
return
new
object
[]
{
s_strPacific
+
"\n"
};
// no trailing newline
yield
return
new
object
[]
{
new
string
(
'a'
,
100
)
};
// long string
yield
return
new
object
[]
{
"/dev/random"
};
yield
return
new
object
[]
{
"Invalid Id"
};
yield
return
new
object
[]
{
"Invalid/Invalid"
};
yield
return
new
object
[]
{
$"./
{
s_strPacific
}
"
};
yield
return
new
object
[]
{
$"
{
s_strPacific
}
/../
{
s_strPacific
}
"
};
}
[
Theory
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录