Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
1696ebb2
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1696ebb2
编写于
8月 14, 2017
作者:
C
cushon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8184940: JDK 9 rejects zip files where the modified day or month is 0
Reviewed-by: martin
上级
507cf097
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
268 addition
and
14 deletion
+268
-14
jdk/src/java.base/share/classes/java/util/zip/ZipUtils.java
jdk/src/java.base/share/classes/java/util/zip/ZipUtils.java
+18
-7
jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java
jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java
+18
-7
jdk/test/java/util/zip/ZipFile/ZeroDate.java
jdk/test/java/util/zip/ZipFile/ZeroDate.java
+112
-0
jdk/test/jdk/nio/zipfs/ZeroDate.java
jdk/test/jdk/nio/zipfs/ZeroDate.java
+120
-0
未找到文件。
jdk/src/java.base/share/classes/java/util/zip/ZipUtils.java
浏览文件 @
1696ebb2
...
...
@@ -81,13 +81,24 @@ class ZipUtils {
* Converts DOS time to Java time (number of milliseconds since epoch).
*/
public
static
long
dosToJavaTime
(
long
dtime
)
{
LocalDateTime
ldt
=
LocalDateTime
.
of
(
(
int
)
(((
dtime
>>
25
)
&
0x7f
)
+
1980
),
(
int
)
((
dtime
>>
21
)
&
0x0f
),
(
int
)
((
dtime
>>
16
)
&
0x1f
),
(
int
)
((
dtime
>>
11
)
&
0x1f
),
(
int
)
((
dtime
>>
5
)
&
0x3f
),
(
int
)
((
dtime
<<
1
)
&
0x3e
));
int
year
;
int
month
;
int
day
;
int
hour
=
(
int
)
((
dtime
>>
11
)
&
0x1f
);
int
minute
=
(
int
)
((
dtime
>>
5
)
&
0x3f
);
int
second
=
(
int
)
((
dtime
<<
1
)
&
0x3e
);
if
((
dtime
>>
16
)
==
0
)
{
// Interpret the 0 DOS date as 1979-11-30 for compatibility with
// other implementations.
year
=
1979
;
month
=
11
;
day
=
30
;
}
else
{
year
=
(
int
)
(((
dtime
>>
25
)
&
0x7f
)
+
1980
);
month
=
(
int
)
((
dtime
>>
21
)
&
0x0f
);
day
=
(
int
)
((
dtime
>>
16
)
&
0x1f
);
}
LocalDateTime
ldt
=
LocalDateTime
.
of
(
year
,
month
,
day
,
hour
,
minute
,
second
);
return
TimeUnit
.
MILLISECONDS
.
convert
(
ldt
.
toEpochSecond
(
ZoneId
.
systemDefault
().
getRules
().
getOffset
(
ldt
)),
TimeUnit
.
SECONDS
);
}
...
...
jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java
浏览文件 @
1696ebb2
...
...
@@ -106,13 +106,24 @@ class ZipUtils {
* Converts DOS time to Java time (number of milliseconds since epoch).
*/
public
static
long
dosToJavaTime
(
long
dtime
)
{
LocalDateTime
ldt
=
LocalDateTime
.
of
(
(
int
)
(((
dtime
>>
25
)
&
0x7f
)
+
1980
),
(
int
)
((
dtime
>>
21
)
&
0x0f
),
(
int
)
((
dtime
>>
16
)
&
0x1f
),
(
int
)
((
dtime
>>
11
)
&
0x1f
),
(
int
)
((
dtime
>>
5
)
&
0x3f
),
(
int
)
((
dtime
<<
1
)
&
0x3e
));
int
year
;
int
month
;
int
day
;
int
hour
=
(
int
)
((
dtime
>>
11
)
&
0x1f
);
int
minute
=
(
int
)
((
dtime
>>
5
)
&
0x3f
);
int
second
=
(
int
)
((
dtime
<<
1
)
&
0x3e
);
if
((
dtime
>>
16
)
==
0
)
{
// Interpret the 0 DOS date as 1979-11-30 for compatibility with
// other implementations.
year
=
1979
;
month
=
11
;
day
=
30
;
}
else
{
year
=
(
int
)
(((
dtime
>>
25
)
&
0x7f
)
+
1980
);
month
=
(
int
)
((
dtime
>>
21
)
&
0x0f
);
day
=
(
int
)
((
dtime
>>
16
)
&
0x1f
);
}
LocalDateTime
ldt
=
LocalDateTime
.
of
(
year
,
month
,
day
,
hour
,
minute
,
second
);
return
TimeUnit
.
MILLISECONDS
.
convert
(
ldt
.
toEpochSecond
(
ZoneId
.
systemDefault
().
getRules
().
getOffset
(
ldt
)),
TimeUnit
.
SECONDS
);
}
...
...
jdk/test/java/util/zip/ZipFile/ZeroDate.java
0 → 100644
浏览文件 @
1696ebb2
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
static
java
.
util
.
zip
.
ZipFile
.
CENOFF
;
import
static
java
.
util
.
zip
.
ZipFile
.
CENTIM
;
import
static
java
.
util
.
zip
.
ZipFile
.
ENDHDR
;
import
static
java
.
util
.
zip
.
ZipFile
.
ENDOFF
;
import
static
java
.
util
.
zip
.
ZipFile
.
LOCTIM
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.util.zip.ZipOutputStream
;
/* @test
* @bug 8184940
* @summary JDK 9 rejects zip files where the modified day or month is 0
* @author Liam Miller-Cushon
*/
public
class
ZeroDate
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// create a zip file, and read it in as a byte array
Path
path
=
Files
.
createTempFile
(
"bad"
,
".zip"
);
try
(
OutputStream
os
=
Files
.
newOutputStream
(
path
);
ZipOutputStream
zos
=
new
ZipOutputStream
(
os
))
{
ZipEntry
e
=
new
ZipEntry
(
"x"
);
zos
.
putNextEntry
(
e
);
zos
.
write
((
int
)
'x'
);
}
int
len
=
(
int
)
Files
.
size
(
path
);
byte
[]
data
=
new
byte
[
len
];
try
(
InputStream
is
=
Files
.
newInputStream
(
path
))
{
is
.
read
(
data
);
}
Files
.
delete
(
path
);
// year, month, day are zero
testDate
(
data
.
clone
(),
0
,
LocalDate
.
of
(
1979
,
11
,
30
));
// only year is zero
testDate
(
data
.
clone
(),
0
<<
25
|
4
<<
21
|
5
<<
16
,
LocalDate
.
of
(
1980
,
4
,
5
));
}
private
static
void
testDate
(
byte
[]
data
,
int
date
,
LocalDate
expected
)
throws
IOException
{
// set the datetime
int
endpos
=
data
.
length
-
ENDHDR
;
int
cenpos
=
u16
(
data
,
endpos
+
ENDOFF
);
int
locpos
=
u16
(
data
,
cenpos
+
CENOFF
);
writeU32
(
data
,
cenpos
+
CENTIM
,
date
);
writeU32
(
data
,
locpos
+
LOCTIM
,
date
);
// ensure that the archive is still readable, and the date is 1979-11-30
Path
path
=
Files
.
createTempFile
(
"out"
,
".zip"
);
try
(
OutputStream
os
=
Files
.
newOutputStream
(
path
))
{
os
.
write
(
data
);
}
try
(
ZipFile
zf
=
new
ZipFile
(
path
.
toFile
()))
{
ZipEntry
ze
=
zf
.
entries
().
nextElement
();
Instant
actualInstant
=
ze
.
getLastModifiedTime
().
toInstant
();
Instant
expectedInstant
=
expected
.
atStartOfDay
().
atZone
(
ZoneId
.
systemDefault
()).
toInstant
();
if
(!
actualInstant
.
equals
(
expectedInstant
))
{
throw
new
AssertionError
(
String
.
format
(
"actual: %s, expected: %s"
,
actualInstant
,
expectedInstant
));
}
}
finally
{
Files
.
delete
(
path
);
}
}
static
int
u8
(
byte
[]
data
,
int
offset
)
{
return
data
[
offset
]
&
0xff
;
}
static
int
u16
(
byte
[]
data
,
int
offset
)
{
return
u8
(
data
,
offset
)
+
(
u8
(
data
,
offset
+
1
)
<<
8
);
}
private
static
void
writeU32
(
byte
[]
data
,
int
pos
,
int
value
)
{
data
[
pos
]
=
(
byte
)
(
value
&
0xff
);
data
[
pos
+
1
]
=
(
byte
)
((
value
>>
8
)
&
0xff
);
data
[
pos
+
2
]
=
(
byte
)
((
value
>>
16
)
&
0xff
);
data
[
pos
+
3
]
=
(
byte
)
((
value
>>
24
)
&
0xff
);
}
}
jdk/test/jdk/nio/zipfs/ZeroDate.java
0 → 100644
浏览文件 @
1696ebb2
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import
static
java
.
util
.
zip
.
ZipFile
.
CENOFF
;
import
static
java
.
util
.
zip
.
ZipFile
.
CENTIM
;
import
static
java
.
util
.
zip
.
ZipFile
.
ENDHDR
;
import
static
java
.
util
.
zip
.
ZipFile
.
ENDOFF
;
import
static
java
.
util
.
zip
.
ZipFile
.
LOCTIM
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.URI
;
import
java.nio.file.FileSystem
;
import
java.nio.file.FileSystems
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.attribute.BasicFileAttributes
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.util.Collections
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
/* @test
* @bug 8184940
* @summary JDK 9 rejects zip files where the modified day or month is 0
* @author Liam Miller-Cushon
*/
public
class
ZeroDate
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// create a zip file, and read it in as a byte array
Path
path
=
Files
.
createTempFile
(
"bad"
,
".zip"
);
try
(
OutputStream
os
=
Files
.
newOutputStream
(
path
);
ZipOutputStream
zos
=
new
ZipOutputStream
(
os
))
{
ZipEntry
e
=
new
ZipEntry
(
"x"
);
zos
.
putNextEntry
(
e
);
zos
.
write
((
int
)
'x'
);
}
int
len
=
(
int
)
Files
.
size
(
path
);
byte
[]
data
=
new
byte
[
len
];
try
(
InputStream
is
=
Files
.
newInputStream
(
path
))
{
is
.
read
(
data
);
}
Files
.
delete
(
path
);
// year, month, day are zero
testDate
(
data
.
clone
(),
0
,
LocalDate
.
of
(
1979
,
11
,
30
));
// only year is zero
testDate
(
data
.
clone
(),
0
<<
25
|
4
<<
21
|
5
<<
16
,
LocalDate
.
of
(
1980
,
4
,
5
));
}
private
static
void
testDate
(
byte
[]
data
,
int
date
,
LocalDate
expected
)
throws
IOException
{
// set the datetime
int
endpos
=
data
.
length
-
ENDHDR
;
int
cenpos
=
u16
(
data
,
endpos
+
ENDOFF
);
int
locpos
=
u16
(
data
,
cenpos
+
CENOFF
);
writeU32
(
data
,
cenpos
+
CENTIM
,
date
);
writeU32
(
data
,
locpos
+
LOCTIM
,
date
);
// ensure that the archive is still readable, and the date is 1979-11-30
Path
path
=
Files
.
createTempFile
(
"out"
,
".zip"
);
try
(
OutputStream
os
=
Files
.
newOutputStream
(
path
))
{
os
.
write
(
data
);
}
URI
uri
=
URI
.
create
(
"jar:file://"
+
path
.
toAbsolutePath
());
try
(
FileSystem
fs
=
FileSystems
.
newFileSystem
(
uri
,
Collections
.
emptyMap
()))
{
Path
entry
=
fs
.
getPath
(
"x"
);
Instant
actualInstant
=
Files
.
readAttributes
(
entry
,
BasicFileAttributes
.
class
)
.
lastModifiedTime
()
.
toInstant
();
Instant
expectedInstant
=
expected
.
atStartOfDay
().
atZone
(
ZoneId
.
systemDefault
()).
toInstant
();
if
(!
actualInstant
.
equals
(
expectedInstant
))
{
throw
new
AssertionError
(
String
.
format
(
"actual: %s, expected: %s"
,
actualInstant
,
expectedInstant
));
}
}
finally
{
Files
.
delete
(
path
);
}
}
static
int
u8
(
byte
[]
data
,
int
offset
)
{
return
data
[
offset
]
&
0xff
;
}
static
int
u16
(
byte
[]
data
,
int
offset
)
{
return
u8
(
data
,
offset
)
+
(
u8
(
data
,
offset
+
1
)
<<
8
);
}
private
static
void
writeU32
(
byte
[]
data
,
int
pos
,
int
value
)
{
data
[
pos
]
=
(
byte
)
(
value
&
0xff
);
data
[
pos
+
1
]
=
(
byte
)
((
value
>>
8
)
&
0xff
);
data
[
pos
+
2
]
=
(
byte
)
((
value
>>
16
)
&
0xff
);
data
[
pos
+
3
]
=
(
byte
)
((
value
>>
24
)
&
0xff
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录