Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
6081db5c
Commit
6081db5c
authored
Jun 19, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ZipHeaderInputStream read sub 5 byte entries correctly
Closes gh-13525
parent
99f993bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
7 deletions
+67
-7
JarWriter.java
...java/org/springframework/boot/loader/tools/JarWriter.java
+15
-7
ZipHeaderPeekInputStreamTests.java
...work/boot/loader/tools/ZipHeaderPeekInputStreamTests.java
+52
-0
No files found.
spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarWriter.java
View file @
6081db5c
...
...
@@ -357,15 +357,15 @@ public class JarWriter implements LoaderClassesWriter {
public
int
read
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
int
read
=
(
this
.
headerStream
!=
null
?
this
.
headerStream
.
read
(
b
,
off
,
len
)
:
-
1
);
if
(
read
>
0
)
{
this
.
position
+=
read
;
}
else
{
read
=
0
;
if
(
read
<=
0
)
{
return
readRemainder
(
b
,
off
,
len
);
}
this
.
position
+=
read
;
if
(
read
<
len
)
{
read
+=
super
.
read
(
b
,
off
+
read
,
len
-
read
);
this
.
position
+=
read
;
int
remainderRead
=
readRemainder
(
b
,
off
+
read
,
len
-
read
);
if
(
remainderRead
>
0
)
{
read
+=
remainderRead
;
}
}
if
(
this
.
position
>=
this
.
headerLength
)
{
this
.
headerStream
=
null
;
...
...
@@ -377,6 +377,14 @@ public class JarWriter implements LoaderClassesWriter {
return
Arrays
.
equals
(
this
.
header
,
ZIP_HEADER
);
}
private
int
readRemainder
(
byte
[]
b
,
int
off
,
int
len
)
throws
IOException
{
int
read
=
super
.
read
(
b
,
off
,
len
);
if
(
read
>
0
)
{
this
.
position
+=
read
;
}
return
read
;
}
}
/**
...
...
spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/ZipHeaderPeekInputStreamTests.java
View file @
6081db5c
...
...
@@ -142,4 +142,56 @@ public class ZipHeaderPeekInputStreamTests {
}
}
@Test
public
void
readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength
()
throws
IOException
{
ZipHeaderPeekInputStream
in
=
null
;
try
{
in
=
new
ZipHeaderPeekInputStream
(
new
ByteArrayInputStream
(
new
byte
[]
{
10
}));
byte
[]
bytes
=
new
byte
[
8
];
assertThat
(
in
.
read
(
bytes
)).
isEqualTo
(
1
);
assertThat
(
bytes
).
containsExactly
(
10
,
0
,
0
,
0
,
0
,
0
,
0
,
0
);
}
finally
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
}
@Test
public
void
readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength
()
throws
IOException
{
ZipHeaderPeekInputStream
in
=
null
;
try
{
in
=
new
ZipHeaderPeekInputStream
(
new
ByteArrayInputStream
(
new
byte
[]
{
1
,
2
,
3
,
4
}));
byte
[]
bytes
=
new
byte
[
8
];
assertThat
(
in
.
read
(
bytes
)).
isEqualTo
(
4
);
assertThat
(
bytes
).
containsExactly
(
1
,
2
,
3
,
4
,
0
,
0
,
0
,
0
);
}
finally
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
}
@Test
public
void
readMoreThanEntireStreamWhenStreamLengthIsZero
()
throws
IOException
{
ZipHeaderPeekInputStream
in
=
null
;
try
{
in
=
new
ZipHeaderPeekInputStream
(
new
ByteArrayInputStream
(
new
byte
[
0
]));
byte
[]
bytes
=
new
byte
[
8
];
assertThat
(
in
.
read
(
bytes
)).
isEqualTo
(-
1
);
assertThat
(
bytes
).
containsExactly
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
);
}
finally
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment