garydgregory commented on code in PR #455:
URL: https://github.com/apache/commons-compress/pull/455#discussion_r1451609748


##########
src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:
##########
@@ -684,6 +715,53 @@ public ZipFile(final String name, final String encoding) 
throws IOException {
         this(new File(name).toPath(), encoding, true);
     }
 
+    private static SeekableByteChannel openZipArchive(Path path, 
ZipOpenOptions options) throws IOException {
+        FileChannel channel = FileChannel.open(path, StandardOpenOption.READ);
+        List<FileChannel> channels = new ArrayList<>();
+        try {
+            boolean is64 = positionAtEndOfCentralDirectoryRecord(channel);
+            long numberOfFiles;
+            if (is64) {
+                channel.position(channel.position() + ZipConstants.WORD + 
ZipConstants.WORD + ZipConstants.DWORD);
+                ByteBuffer buf = ByteBuffer.allocate(ZipConstants.WORD);
+                buf.order(ByteOrder.LITTLE_ENDIAN);
+                IOUtils.readFully(channel, buf);
+                buf.flip();
+                numberOfFiles = buf.getInt() & 0xffffffffL;
+            } else {
+                channel.position(channel.position() + ZipConstants.WORD);
+                ByteBuffer buf = ByteBuffer.allocate(ZipConstants.SHORT);
+                buf.order(ByteOrder.LITTLE_ENDIAN);
+                IOUtils.readFully(channel, buf);
+                buf.flip();
+                numberOfFiles = (buf.getShort() & 0xffff) + 1;

Review Comment:
   It looks like other methods in this file use `ZipLong.getValue(ByteBuffer)` 
to get this value. Should this call site do the same?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to