@@ -151,9 +151,9 @@ class ZipFileSystem extends FileSystem {
151151 this .forceEnd64 = isTrue (env , "forceZIP64End" );
152152 this .defaultCompressionMethod = getDefaultCompressionMethod (env );
153153 this .supportPosix = isTrue (env , PROPERTY_POSIX );
154- this .defaultOwner = initOwner (zfpath , env );
155- this .defaultGroup = initGroup (zfpath , env );
156- this .defaultPermissions = initPermissions (env );
154+ this .defaultOwner = supportPosix ? initOwner (zfpath , env ) : null ;
155+ this .defaultGroup = supportPosix ? initGroup (zfpath , env ) : null ;
156+ this .defaultPermissions = supportPosix ? initPermissions (env ) : null ;
157157 this .supportedFileAttributeViews = supportPosix ?
158158 Set .of ("basic" , "posix" , "zip" ) : Set .of ("basic" , "zip" );
159159 if (Files .notExists (zfpath )) {
@@ -1575,9 +1575,9 @@ private byte[] initCEN() throws IOException {
15751575 throw new ZipException ("invalid CEN header (bad header size)" );
15761576 }
15771577 IndexNode inode = new IndexNode (cen , pos , nlen );
1578- if (hasDotOrDotDot ( inode .name )) {
1578+ if (inode .pathHasDotOrDotDot ( )) {
15791579 throw new ZipException ("ZIP file can't be opened as a file system " +
1580- "because an entry has a '.' or '..' element in its name" );
1580+ "because entry \" " + inode . nameAsString () + " \" has a '.' or '..' element in its name" );
15811581 }
15821582 inodes .put (inode , inode );
15831583 if (zc .isUTF8 () || (flag & FLAG_USE_UTF8 ) != 0 ) {
@@ -1595,44 +1595,6 @@ private byte[] initCEN() throws IOException {
15951595 return cen ;
15961596 }
15971597
1598- /**
1599- * Check Inode.name to see if it includes a "." or ".." in the name array
1600- * @param path the path as stored in Inode.name to verify
1601- * @return true if the path contains a "." or ".." entry; false otherwise
1602- */
1603- private boolean hasDotOrDotDot (byte [] path ) {
1604- // Inode.name always includes "/" in path[0]
1605- assert path [0 ] == '/' ;
1606- if (path .length == 1 ) {
1607- return false ;
1608- }
1609- int index = 1 ;
1610- while (index < path .length ) {
1611- int starting = index ;
1612- while (index < path .length && path [index ] != '/' ) {
1613- index ++;
1614- }
1615- // Check the path snippet for a "." or ".."
1616- if (isDotOrDotDotPath (path , starting , index )) {
1617- return true ;
1618- }
1619- index ++;
1620- }
1621- return false ;
1622- }
1623-
1624- /**
1625- * Check the path to see if it includes a "." or ".."
1626- * @param path the path to check
1627- * @return true if the path contains a "." or ".." entry; false otherwise
1628- */
1629- private boolean isDotOrDotDotPath (byte [] path , int start , int index ) {
1630- int pathLen = index - start ;
1631- if ((pathLen == 1 && path [start ] == '.' ))
1632- return true ;
1633- return (pathLen == 2 && path [start ] == '.' ) && path [start + 1 ] == '.' ;
1634- }
1635-
16361598 private final void checkUTF8 (byte [] a ) throws ZipException {
16371599 try {
16381600 int end = a .length ;
@@ -2653,6 +2615,37 @@ boolean isDir() {
26532615 return isdir ;
26542616 }
26552617
2618+ /**
2619+ * Check name if it contains a "." or ".." path element
2620+ * @return true if the path contains a "." or ".." entry; false otherwise
2621+ */
2622+ private boolean pathHasDotOrDotDot () {
2623+ // name always includes "/" in path[0]
2624+ assert name [0 ] == '/' ;
2625+ if (name .length == 1 ) {
2626+ return false ;
2627+ }
2628+ int index = 1 ;
2629+ while (index < name .length ) {
2630+ int start = index ;
2631+ while (index < name .length && name [index ] != '/' ) {
2632+ index ++;
2633+ }
2634+ if (name [start ] == '.' ) {
2635+ int len = index - start ;
2636+ if (len == 1 || (name [start + 1 ] == '.' && len == 2 )) {
2637+ return true ;
2638+ }
2639+ }
2640+ index ++;
2641+ }
2642+ return false ;
2643+ }
2644+
2645+ protected String nameAsString () {
2646+ return new String (name );
2647+ }
2648+
26562649 @ Override
26572650 public boolean equals (Object other ) {
26582651 if (!(other instanceof IndexNode )) {
@@ -2671,7 +2664,7 @@ public int hashCode() {
26712664
26722665 @ Override
26732666 public String toString () {
2674- return new String ( name ) + (isdir ? " (dir)" : " " ) + ", index: " + pos ;
2667+ return nameAsString ( ) + (isdir ? " (dir)" : " " ) + ", index: " + pos ;
26752668 }
26762669 }
26772670
@@ -3207,7 +3200,7 @@ private void readLocEXTT(ZipFileSystem zipfs) throws IOException {
32073200 public String toString () {
32083201 StringBuilder sb = new StringBuilder (1024 );
32093202 Formatter fm = new Formatter (sb );
3210- fm .format (" name : %s%n" , new String ( name ));
3203+ fm .format (" name : %s%n" , nameAsString ( ));
32113204 fm .format (" creationTime : %tc%n" , creationTime ().toMillis ());
32123205 fm .format (" lastAccessTime : %tc%n" , lastAccessTime ().toMillis ());
32133206 fm .format (" lastModifiedTime: %tc%n" , lastModifiedTime ().toMillis ());
0 commit comments