Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
2f63ffc9
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2f63ffc9
编写于
8月 21, 2013
作者:
V
valeriep
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8022927: Input validation for byte/endian conversions
Summary: Add additional boundary checks Reviewed-by: ascarpino
上级
335a20a4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
45 addition
and
6 deletion
+45
-6
src/share/classes/sun/security/provider/ByteArrayAccess.java
src/share/classes/sun/security/provider/ByteArrayAccess.java
+45
-6
未找到文件。
src/share/classes/sun/security/provider/ByteArrayAccess.java
浏览文件 @
2f63ffc9
/*
/*
* Copyright (c) 2006, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -43,10 +43,8 @@ import sun.misc.Unsafe;
...
@@ -43,10 +43,8 @@ import sun.misc.Unsafe;
* These are the only platforms we currently support, but other optimized
* These are the only platforms we currently support, but other optimized
* variants could be added as needed.
* variants could be added as needed.
*
*
* NOTE that because this code performs unchecked direct memory access, it
* NOTE that ArrayIndexOutOfBoundsException will be thrown if the bounds checks
* MUST be restricted to trusted code. It is imperative that the caller protects
* failed.
* against out of bounds memory access by performing the necessary bounds
* checks before calling methods in this class.
*
*
* This class may also be helpful in improving the performance of the
* This class may also be helpful in improving the performance of the
* crypto code in the SunJCE provider. However, for now it is only accessible by
* crypto code in the SunJCE provider. However, for now it is only accessible by
...
@@ -103,6 +101,10 @@ final class ByteArrayAccess {
...
@@ -103,6 +101,10 @@ final class ByteArrayAccess {
* byte[] to int[] conversion, little endian byte order.
* byte[] to int[] conversion, little endian byte order.
*/
*/
static
void
b2iLittle
(
byte
[]
in
,
int
inOfs
,
int
[]
out
,
int
outOfs
,
int
len
)
{
static
void
b2iLittle
(
byte
[]
in
,
int
inOfs
,
int
[]
out
,
int
outOfs
,
int
len
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
len
)
||
(
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
len
/
4
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
inOfs
+=
byteArrayOfs
;
inOfs
+=
byteArrayOfs
;
len
+=
inOfs
;
len
+=
inOfs
;
...
@@ -131,6 +133,10 @@ final class ByteArrayAccess {
...
@@ -131,6 +133,10 @@ final class ByteArrayAccess {
// Special optimization of b2iLittle(in, inOfs, out, 0, 64)
// Special optimization of b2iLittle(in, inOfs, out, 0, 64)
static
void
b2iLittle64
(
byte
[]
in
,
int
inOfs
,
int
[]
out
)
{
static
void
b2iLittle64
(
byte
[]
in
,
int
inOfs
,
int
[]
out
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
64
)
||
(
out
.
length
<
16
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
inOfs
+=
byteArrayOfs
;
inOfs
+=
byteArrayOfs
;
out
[
0
]
=
unsafe
.
getInt
(
in
,
(
long
)(
inOfs
));
out
[
0
]
=
unsafe
.
getInt
(
in
,
(
long
)(
inOfs
));
...
@@ -176,6 +182,10 @@ final class ByteArrayAccess {
...
@@ -176,6 +182,10 @@ final class ByteArrayAccess {
* int[] to byte[] conversion, little endian byte order.
* int[] to byte[] conversion, little endian byte order.
*/
*/
static
void
i2bLittle
(
int
[]
in
,
int
inOfs
,
byte
[]
out
,
int
outOfs
,
int
len
)
{
static
void
i2bLittle
(
int
[]
in
,
int
inOfs
,
byte
[]
out
,
int
outOfs
,
int
len
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
len
/
4
)
||
(
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
len
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
outOfs
+=
byteArrayOfs
;
outOfs
+=
byteArrayOfs
;
len
+=
outOfs
;
len
+=
outOfs
;
...
@@ -204,6 +214,9 @@ final class ByteArrayAccess {
...
@@ -204,6 +214,9 @@ final class ByteArrayAccess {
// Store one 32-bit value into out[outOfs..outOfs+3] in little endian order.
// Store one 32-bit value into out[outOfs..outOfs+3] in little endian order.
static
void
i2bLittle4
(
int
val
,
byte
[]
out
,
int
outOfs
)
{
static
void
i2bLittle4
(
int
val
,
byte
[]
out
,
int
outOfs
)
{
if
((
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
4
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
unsafe
.
putInt
(
out
,
(
long
)(
byteArrayOfs
+
outOfs
),
val
);
unsafe
.
putInt
(
out
,
(
long
)(
byteArrayOfs
+
outOfs
),
val
);
}
else
if
(
bigEndian
&&
((
outOfs
&
3
)
==
0
))
{
}
else
if
(
bigEndian
&&
((
outOfs
&
3
)
==
0
))
{
...
@@ -220,6 +233,10 @@ final class ByteArrayAccess {
...
@@ -220,6 +233,10 @@ final class ByteArrayAccess {
* byte[] to int[] conversion, big endian byte order.
* byte[] to int[] conversion, big endian byte order.
*/
*/
static
void
b2iBig
(
byte
[]
in
,
int
inOfs
,
int
[]
out
,
int
outOfs
,
int
len
)
{
static
void
b2iBig
(
byte
[]
in
,
int
inOfs
,
int
[]
out
,
int
outOfs
,
int
len
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
len
)
||
(
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
len
/
4
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
inOfs
+=
byteArrayOfs
;
inOfs
+=
byteArrayOfs
;
len
+=
inOfs
;
len
+=
inOfs
;
...
@@ -248,6 +265,10 @@ final class ByteArrayAccess {
...
@@ -248,6 +265,10 @@ final class ByteArrayAccess {
// Special optimization of b2iBig(in, inOfs, out, 0, 64)
// Special optimization of b2iBig(in, inOfs, out, 0, 64)
static
void
b2iBig64
(
byte
[]
in
,
int
inOfs
,
int
[]
out
)
{
static
void
b2iBig64
(
byte
[]
in
,
int
inOfs
,
int
[]
out
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
64
)
||
(
out
.
length
<
16
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
inOfs
+=
byteArrayOfs
;
inOfs
+=
byteArrayOfs
;
out
[
0
]
=
reverseBytes
(
unsafe
.
getInt
(
in
,
(
long
)(
inOfs
)));
out
[
0
]
=
reverseBytes
(
unsafe
.
getInt
(
in
,
(
long
)(
inOfs
)));
...
@@ -293,6 +314,10 @@ final class ByteArrayAccess {
...
@@ -293,6 +314,10 @@ final class ByteArrayAccess {
* int[] to byte[] conversion, big endian byte order.
* int[] to byte[] conversion, big endian byte order.
*/
*/
static
void
i2bBig
(
int
[]
in
,
int
inOfs
,
byte
[]
out
,
int
outOfs
,
int
len
)
{
static
void
i2bBig
(
int
[]
in
,
int
inOfs
,
byte
[]
out
,
int
outOfs
,
int
len
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
len
/
4
)
||
(
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
len
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
outOfs
+=
byteArrayOfs
;
outOfs
+=
byteArrayOfs
;
len
+=
outOfs
;
len
+=
outOfs
;
...
@@ -321,6 +346,9 @@ final class ByteArrayAccess {
...
@@ -321,6 +346,9 @@ final class ByteArrayAccess {
// Store one 32-bit value into out[outOfs..outOfs+3] in big endian order.
// Store one 32-bit value into out[outOfs..outOfs+3] in big endian order.
static
void
i2bBig4
(
int
val
,
byte
[]
out
,
int
outOfs
)
{
static
void
i2bBig4
(
int
val
,
byte
[]
out
,
int
outOfs
)
{
if
((
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
4
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
unsafe
.
putInt
(
out
,
(
long
)(
byteArrayOfs
+
outOfs
),
reverseBytes
(
val
));
unsafe
.
putInt
(
out
,
(
long
)(
byteArrayOfs
+
outOfs
),
reverseBytes
(
val
));
}
else
if
(
bigEndian
&&
((
outOfs
&
3
)
==
0
))
{
}
else
if
(
bigEndian
&&
((
outOfs
&
3
)
==
0
))
{
...
@@ -337,6 +365,10 @@ final class ByteArrayAccess {
...
@@ -337,6 +365,10 @@ final class ByteArrayAccess {
* byte[] to long[] conversion, big endian byte order.
* byte[] to long[] conversion, big endian byte order.
*/
*/
static
void
b2lBig
(
byte
[]
in
,
int
inOfs
,
long
[]
out
,
int
outOfs
,
int
len
)
{
static
void
b2lBig
(
byte
[]
in
,
int
inOfs
,
long
[]
out
,
int
outOfs
,
int
len
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
len
)
||
(
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
len
/
8
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
inOfs
+=
byteArrayOfs
;
inOfs
+=
byteArrayOfs
;
len
+=
inOfs
;
len
+=
inOfs
;
...
@@ -378,6 +410,10 @@ final class ByteArrayAccess {
...
@@ -378,6 +410,10 @@ final class ByteArrayAccess {
// Special optimization of b2lBig(in, inOfs, out, 0, 128)
// Special optimization of b2lBig(in, inOfs, out, 0, 128)
static
void
b2lBig128
(
byte
[]
in
,
int
inOfs
,
long
[]
out
)
{
static
void
b2lBig128
(
byte
[]
in
,
int
inOfs
,
long
[]
out
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
128
)
||
(
out
.
length
<
16
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
if
(
littleEndianUnaligned
)
{
if
(
littleEndianUnaligned
)
{
inOfs
+=
byteArrayOfs
;
inOfs
+=
byteArrayOfs
;
out
[
0
]
=
reverseBytes
(
unsafe
.
getLong
(
in
,
(
long
)(
inOfs
)));
out
[
0
]
=
reverseBytes
(
unsafe
.
getLong
(
in
,
(
long
)(
inOfs
)));
...
@@ -406,6 +442,10 @@ final class ByteArrayAccess {
...
@@ -406,6 +442,10 @@ final class ByteArrayAccess {
* long[] to byte[] conversion, big endian byte order.
* long[] to byte[] conversion, big endian byte order.
*/
*/
static
void
l2bBig
(
long
[]
in
,
int
inOfs
,
byte
[]
out
,
int
outOfs
,
int
len
)
{
static
void
l2bBig
(
long
[]
in
,
int
inOfs
,
byte
[]
out
,
int
outOfs
,
int
len
)
{
if
((
inOfs
<
0
)
||
((
in
.
length
-
inOfs
)
<
len
/
8
)
||
(
outOfs
<
0
)
||
((
out
.
length
-
outOfs
)
<
len
))
{
throw
new
ArrayIndexOutOfBoundsException
();
}
len
+=
outOfs
;
len
+=
outOfs
;
while
(
outOfs
<
len
)
{
while
(
outOfs
<
len
)
{
long
i
=
in
[
inOfs
++];
long
i
=
in
[
inOfs
++];
...
@@ -419,5 +459,4 @@ final class ByteArrayAccess {
...
@@ -419,5 +459,4 @@ final class ByteArrayAccess {
out
[
outOfs
++]
=
(
byte
)(
i
);
out
[
outOfs
++]
=
(
byte
)(
i
);
}
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录