Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,36 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
${argLine} --add-opens java.base/java.io=ALL-UNNAMED
</argLine>
</configuration>
<!-- we need jdk > 16 to pass on LegacyContstructorsTest so
we need \-\-add-opens generally. However, we want to test
that unpack200 works with jdk > 16 without \-\-add-opens-->
<executions>
<execution>
<id>default-test</id>
<configuration>
<argLine>
${argLine} --add-opens java.base/java.io=ALL-UNNAMED
</argLine>
<excludes>
<exclude>**/harmony/unpack200/**</exclude>
<!-- Needs low memory: -Xmx80m -->
<exclude>**/SevenZReadSubStreamsInfoTest.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>pack200-tests</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<argLine>${argLine}</argLine>
<includes>
<include>**/harmony/unpack200/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public Archive(final InputStream inputStream, final JarOutputStream outputStream
this.inputStream = Pack200UnpackerAdapter.newBoundedInputStream(inputStream);
this.outputStream = outputStream;
if (inputStream instanceof FileInputStream) {
inputPath = Paths.get(Pack200UnpackerAdapter.readPathString((FileInputStream) inputStream));
final String pathString = Pack200UnpackerAdapter.readPathString((FileInputStream) inputStream);
inputPath = pathString != null ? Paths.get(pathString) : null;
} else {
inputPath = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,26 @@ static BoundedInputStream newBoundedInputStream(final File file) throws IOExcept
return newBoundedInputStream(file.toPath());
}

@SuppressWarnings("resource") // Caller closes.
private static BoundedInputStream newBoundedInputStream(final FileInputStream fileInputStream) throws IOException {
return newBoundedInputStream(readPathString(fileInputStream));
final String pathString = readPathString(fileInputStream);
if (pathString != null) {
return newBoundedInputStream(pathString);
}
// Reflection failed (e.g., Java 17+ strong encapsulation), fall back to channel size.
try {
final long size = fileInputStream.getChannel().size();
// @formatter:off
return BoundedInputStream.builder()
.setInputStream(new BufferedInputStream(fileInputStream))
.setMaxCount(size)
.setPropagateClose(false)
.get();
// @formatter:on
} catch (final IOException e) {
// No limit
return BoundedInputStream.builder().setInputStream(new BufferedInputStream(fileInputStream)).get();
}
}

@SuppressWarnings("resource") // Caller closes.
Expand All @@ -74,7 +92,10 @@ static BoundedInputStream newBoundedInputStream(final InputStream inputStream) t
return newBoundedInputStream(BoundedInputStream.builder().setInputStream(inputStream).get());
}
if (inputStream instanceof FilterInputStream) {
return newBoundedInputStream(unwrap((FilterInputStream) inputStream));
final InputStream unwrapped = unwrap((FilterInputStream) inputStream);
if (unwrapped != null) {
return newBoundedInputStream(unwrapped);
}
}
if (inputStream instanceof FileInputStream) {
return newBoundedInputStream((FileInputStream) inputStream);
Expand Down Expand Up @@ -140,6 +161,13 @@ private static <T> T readField(final Object object, final String fieldName) {
return (T) FieldUtils.readField(object, fieldName, true);
} catch (final IllegalAccessException e) {
return null;
} catch (final RuntimeException e) {
// InaccessibleObjectException (Java 9+) extends RuntimeException, not IllegalAccessException.
// Thrown when Java 17+ strong encapsulation blocks setAccessible on JDK internal fields.
if ("java.lang.reflect.InaccessibleObjectException".equals(e.getClass().getName())) {
return null;
}
throw e;
}
}

Expand Down
Loading